2014-02-12 152 views
-1

目前還不清楚什麼是正確的語法,我已經嘗試過一些例子,但沒有運氣,這是我當前的按鈕代碼工作,我需要它保持作爲在新窗口/新標籤MVC按鈕應該在新窗口/標籤頁中打開url

<input type="button" title="Read" value="@T("Account.DownloadableProducts.Read")" onclick="location.href='@Url.Action("GetDownload", "Download", new { orderItemId = Model.DownloadMappingIds[product.Id].guid })'" /> 

感謝

回答

4

您可以使用JavaScript函數

<input type="button" value="MyButton" onclick="myfunction(this)" 
data-myurl="@Url.Action("aa", "bb", new { [email protected]})" /> 


    <script> 
    function myfunction(e) 
    { 
    var url = $(e).data('myurl'); 
    var popupWindow = window.open(url,title,'scrollbars=1,height=650,width=1050'); 
    } 
    </script> 
+2

太好了。對於我們其他人不太瞭解MVC,「aa」和「bb」是什麼?您應該擁有像@ Url.Action(「Read」,「MyController」,new {id = @ id})。對不起,只是我的寵物,人們認爲我們知道的東西馬上,而不是完成的例子。 – vapcguy

+0

對此的一種變化:這可能會變得更加混亂,但不是@ Url.Action,您可以只說'data-myurl =「/ OtherBranch/Index?id = @ id」'並將其重定向到'myfunction ()'''var newUrl = window.location.href.split('/ FirstBranch')[0] + e.attr('data-myurl');' – vapcguy

0

我掙扎閱讀你的問題和代碼,但打開新窗口點擊打開時的動作按鈕,下面的代碼被用於:

target = "_blank" 

是否可以整理你的問題,然後我可以進一步幫助你。

1

我一直在掙扎了一會兒做這個,解決辦法是,而不是目標=「_空白」,你應該formtarget使用=「_空白」。

謝謝!

相關問題