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

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

问题描述

我有一个 ASP.NET MVC 应用程序,它在新的浏览器窗口中打开一个请求"视图.当用户提交表单时,我希望窗口关闭.保存请求信息后,我的 RequestController 代码应该如何关闭窗口?我不确定控制器操作应该返回什么.

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 结果),但我更喜欢前者.

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天全站免登陆