你如何从控制器关闭一个ASP.NET MVC页? [英] How do you close an ASP.NET MVC page from the controller?

查看:149
本文介绍了你如何从控制器关闭一个ASP.NET MVC页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打开一个新的浏览器窗口中的请求视图中的ASP.NET MVC应用程序。当用户提交表单,我想窗口关闭。我应该我RequestController code模样保存请求信息后,关闭窗口?我不知道什么控制器动作应该返回。

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.

推荐答案

您可以返回具有以下JavaScript中的视图(或者你可以返回一个JavaScript的结果),但我preFER前者。

You could return a View that has the following javascript (or you could return a JavaScript result) but I prefer the former.

public ActionResult SubmitForm()
{
    return View("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

public ActionResult SubmitForm()
{
    return JavaScript("window.close();");
}

这篇关于你如何从控制器关闭一个ASP.NET MVC页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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