簡體   English   中英

在新窗口中從JavaScript打開MVC 4視圖

[英]open an mvc 4 view from javascript in a new window

我正在嘗試在mvc 4中使用javascript打開一個新窗口(window.open)。這是我當前的代碼:

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

這不會打開新窗口。 它使網址為“ ReportExecution / Index?target = _blank”。 我嘗試使用:

window.open

代替

window.location.href

但這沒用。 如何做到這一點?

好的,因此這段代碼可用於在javascript中打開新的MVC 4視圖:

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

您的代碼看起來不錯,但是new {target="_blank"})是多余的。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM