javascript - 如何关闭弹出窗口并将 View 模型返回到先前的 View ?

标签 javascript c# asp.net-mvc

在我的 MVC5 应用程序中,我打开一个如下所示的弹出窗口:

<script type="text/javascript">
    function openNewWindow(e) {
        e.preventDefault();
        window.open("/Index/PopUp", "New Window", "height=700,width=500");
        return false;
    }
</script>

In the pop-up I made a selection on some data & want a to return a view model to the previous view - is this possible?

我开始认为使用弹出窗口可能不是最好的主意,但我有兴趣了解任何可能的解决方案......

最佳答案

为打开的窗口分配全局引用,使用.close()关闭打开的窗口

<script type="text/javascript">
    window.popup = void 0;
    function openNewWindow(e) {
        e.preventDefault();
        window.popup = window.open("/Index/PopUp", "New Window", "height=700,width=500");
        return false;
    }
    // do stuff after call to `openNewWindow`
    // close `window.popup`
    // window.popup.close();
</script>

关于javascript - 如何关闭弹出窗口并将 View 模型返回到先前的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41163008/

相关文章:

asp.net - 标准 .NET CMS 系统可以与 ASP.NET MVC 一起使用吗

javascript - Google Sheets 带注释的时间线显示精确值?

javascript - Req.Body 返回 "undefined"值

c# - 从 Sharepoint 中的数据库快速读取 SQL 以获取设置值的最佳实践

c# - 拖放效果.滚动 : why -2147483648 not 8?

c# - 在 asp.net-mvc 中创建可重用部分的最佳方法

javascript - jQuery在计算窗口高度后将div放置在特定位置

javascript - 将 php 变量从 js 传递到 php 并返回内容问题

c# - 检测何时在 Windows 窗体的标题栏中按下帮助按钮?

html - 如何生成带图标的 Html.ActionLink