2015-04-03 176 views
0

如果提交按鈕位於@using Html.BeginForm中,是否有任何方法可以打開新窗口?我嘗試了以下,但它不起作用?如何使用Html.BeginForm打開新窗口

@using (Html.BeginForm("SetCol", "Document", FormMethod.Post, new {target="_blank"})){ 
<div class="modal-body" data-height-relative="20"> 
. 
. 
. 
</div> 
    <div class="modal-footer"> 
     <div class="pull-right"> 
      <input type="submit" value="Senden" class="btn btn-primary"/> 
      <a href="@ViewData["closeUrl"]" class="btn btn-primary" @(ViewData["closeUrl"] == "#" ? "data-dismiss=modal" : "")>@Translations.Close</a> 
     </div> 
    </div> 
} 

輸出爲PDF文件:

<html> 
    <body marginwidth="0" marginheight="0" style="background-color: rgb(38,38,38)"> 
<embed width="100%" height="100%" name="plugin" src="http://localhost:54906/Document/SetCol?id=108" type="application/pdf"> 
    </body> 
</html> 
+0

可能重複[Javascript Post on Form提交打開新窗口](http://stackoverflow.com/questions/178964/javascript-post-on-form-submit-open-a-new-window) – CodeCaster 2015-04-03 09:46:19

+0

你有錯誤的目標,你需要'_blank'而不是'_self'。但請不要這樣做,這是糟糕的用戶體驗。 – CodeCaster 2015-04-03 09:47:07

+0

我嘗試過blank_,但仍然在相同的窗口中看到結果。爲什麼是可怕的,有什麼選擇? – user576914 2015-04-03 09:49:46

回答

2

下面一行對我的作品與您的代碼。可能與你的行動方法有關。

@using (Html.BeginForm("About", "Home", FormMethod.Post, new { target = "_blank" })) 

正如您在您的評論中提到,該方法返回一個PDF文件,你可以使用window.open,如:

window.open("../Document/SetCol", "_blank"); 

window.open("@Url.Action("LoadReport", "ExportReport")" + link, "_blank"); 

你必須定義一個點擊事件處理器顯然。

+0

有沒有VB的等價物? – Kixoka 2017-03-03 20:51:38