2014-02-12 155 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使用=“_空白”。

谢谢!

相关问题