ASP.Net MVC 3控制器操作和打开新窗口

时间:2022-06-09 21:16:11

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.

所以我的控制器执行操作并打开一个新窗口。

anyone can help me ?

有人可以帮帮我吗?

thanks

1 个解决方案

#1


16  

Technically, this can be done by returning javascript that will open the new window.

从技术上讲,这可以通过返回将打开新窗口的javascript来完成。

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"})

Edit

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.

我可以从你的行动中看出,它可能是一个创建报告的表格;您也可以在表单上使用属性target ='_ blank'。

#1


16  

Technically, this can be done by returning javascript that will open the new window.

从技术上讲,这可以通过返回将打开新窗口的javascript来完成。

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"})

Edit

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.

我可以从你的行动中看出,它可能是一个创建报告的表格;您也可以在表单上使用属性target ='_ blank'。