ASP.Net MVC 3 控制器动作和打开新窗口 [英] ASP.Net MVC 3 Controller Action and Open New Window
问题描述
我有一个控制器和一个动作.这个动作是将数据保存到数据库中.现在,我希望当我提交一个按钮时,我的控制器执行一个操作并打开新窗口.
i have a controller and an action. this action is to save data into database. and now, i want when i submit a button, my controller do an action and open new window.
public ActionResult New(FormCollection collection)
{
data.Population_Code = collection["Countrys[0].CountryCode"];
data.Population_Desc = collection["Countrys[0].CountryDesc"];
data.Population_Grouping = collection["Countrys[0].CountryGroup"];
data.Population_Type = "CNTRY";
data.Population_Redudant = "N";
data.Population_Modified_At = officeCode.User_Office.ToString();
db.SaveChanges();
//example for new window
//window.open('/Report/New.aspx')
return RedirectToAction("index");
}
所以我的控制器执行一个操作并打开一个新窗口.
so my controller do an action and open a new window.
有人可以帮我吗?
谢谢
推荐答案
从技术上讲,这可以通过返回将打开新窗口的 javascript 来完成.
Technically, this can be done by returning javascript that will open the new window.
但是,大多数浏览器都会终止以这种方式调用的新窗口(即弹出窗口阻止程序).
However, most browsers will kill a new window called in this manner (i.e. popup blocker).
如果可能的话,最好从一开始就在新窗口中打开指向您的操作的链接;
You would be better off, if possible, by opening the link to your action in a new window from the start;
@Html.ActionLink("New report", "New", "Report", null, new {target = "_blank"})
编辑
我可以从你的行为中看出,它可能是创建报告的表单;您还可以在表单上使用属性 target='_blank'
.
I can see from your action, that it is probably a form that creates the report; you can also use the attribute target='_blank'
on a form as well.
这篇关于ASP.Net MVC 3 控制器动作和打开新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!