ASP.Net MVC 3控制器动作,并打开新窗口 [英] ASP.Net MVC 3 Controller Action and Open New Window

查看:2613
本文介绍了ASP.Net MVC 3控制器动作,并打开新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制器和一个动作。这个动作是将数据保存到数据库中。现在,我想,当我提交按钮,我的控制器做一个动作和开放的新窗口。

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

修改

我可以从你的行动看,这可能是创建报表的形式;你也可以使用属性目标='_空白表单上为好。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆