I have an ASP.NET MVC app that opens a "Request" view in a new browser window. When the user submits the form, I'd like the window to close. What should my RequestController code look like to close the window after saving the request information? I'm not sure what the controller action should be returning.
我有一个ASP.NET MVC应用程序,在新的浏览器窗口中打开“请求”视图。当用户提交表单时,我希望窗口关闭。在保存请求信息后,我的RequestController代码应该如何关闭窗口?我不确定控制器动作应该返回什么。
5 个解决方案
#1
25
You could return a View that has the following javascript (or you could return a JavaScript result) but I prefer the former.
您可以返回具有以下javascript的视图(或者您可以返回JavaScript结果),但我更喜欢前者。
public ActionResult SubmitForm()
{
return View("Close");
}
View for Close:
查看关闭:
<body>
<script type="text/javascript">
window.close();
</script>
</body>
Here is a way to do it directly in your Controller but I advise against it
这是一种直接在Controller中执行此操作的方法,但我建议不要这样做
public ActionResult SubmitForm()
{
return JavaScript("window.close();");
}
#2
3
Like such:
像这样:
[HttpPost]
public ActionResult MyController(Model model)
{
//do stuff
ViewBag.Processed = true;
return View();
}
The view:
风景:
<%if(null!=ViewBag.Processed && (bool)ViewBag.Processed == true){%>
<script>
window.close();
</script>
<%}%>
#3
2
It sounds like you could return an almost empty View template that simply had some javascript in the header that just ran "window.close()".
听起来你可以返回一个几乎是空的View模板,它只是在标题中只有一些javascript运行“window.close()”。
#4
0
This worked for me to close the window.
这对我有用,可以关闭窗口。
Controller:
控制器:
return PartialView("_LoginSuccessPartial");
View:
视图:
<script>
var loginwindow = $("#loginWindow").data("kendoWindow");
loginwindow.close();
</script>
#5
-1
Using this you can close the window like this:
使用它你可以这样关闭窗口:
return Content("<script language='javascript'>window.close();</script>");
#1
25
You could return a View that has the following javascript (or you could return a JavaScript result) but I prefer the former.
您可以返回具有以下javascript的视图(或者您可以返回JavaScript结果),但我更喜欢前者。
public ActionResult SubmitForm()
{
return View("Close");
}
View for Close:
查看关闭:
<body>
<script type="text/javascript">
window.close();
</script>
</body>
Here is a way to do it directly in your Controller but I advise against it
这是一种直接在Controller中执行此操作的方法,但我建议不要这样做
public ActionResult SubmitForm()
{
return JavaScript("window.close();");
}
#2
3
Like such:
像这样:
[HttpPost]
public ActionResult MyController(Model model)
{
//do stuff
ViewBag.Processed = true;
return View();
}
The view:
风景:
<%if(null!=ViewBag.Processed && (bool)ViewBag.Processed == true){%>
<script>
window.close();
</script>
<%}%>
#3
2
It sounds like you could return an almost empty View template that simply had some javascript in the header that just ran "window.close()".
听起来你可以返回一个几乎是空的View模板,它只是在标题中只有一些javascript运行“window.close()”。
#4
0
This worked for me to close the window.
这对我有用,可以关闭窗口。
Controller:
控制器:
return PartialView("_LoginSuccessPartial");
View:
视图:
<script>
var loginwindow = $("#loginWindow").data("kendoWindow");
loginwindow.close();
</script>
#5
-1
Using this you can close the window like this:
使用它你可以这样关闭窗口:
return Content("<script language='javascript'>window.close();</script>");