【问题标题】:open an mvc 4 view from javascript in a new window在新窗口中从 javascript 打开一个 mvc 4 视图
【发布时间】:2015-12-07 16:52:30
【问题描述】:

我正在尝试在 mvc 4 中使用 javascript 打开一个新窗口 (window.open)。这是我当前的代码:

                var url = '@Url.Action("Index", "ReportExecution", new {target="_blank"})';
            window.location.href = url;

这不会打开一个新窗口。它使 url “ReportExecution/Index?target=_blank”。我尝试使用:

window.open

而不是

window.location.href

但这没有用。这如何实现?

【问题讨论】:

    标签: javascript asp.net-mvc asp.net-mvc-4


    【解决方案1】:

    好的,所以这段代码适用于在 javascript 中打开一个新的 MVC 4 视图:

    window.open('@Url.Action("Index", "ReportExecution")');
    

    【讨论】:

      【解决方案2】:

      您的代码看起来不错,但 new {target="_blank"}) 是多余的。

      <script type="text/javascript">
         var url = '@Url.Action("Index", "ReportExecution")';
         window.open(url, '_blank');
      </script>
      

      【讨论】:

      • 从我的回答中可以看出,你不能使用target="_blank"。这不是多余的,它实际上变成了url的参数。如果您查看我的答案,我会按照您所做的那样仅以较短的形式对其进行修复。
      猜你喜欢
      • 1970-01-01
      • 2013-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      • 2018-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多