MVC 按钮应在新窗口/选项卡中打开 url

k-m*_*man 0 asp.net-mvc button target

目前尚不清楚正确的语法应该是什么,我已经尝试了一些示例,但没有运气,这是我当前可以工作的按钮代码,我需要它在单击时保持作为按钮在新窗口/新选项卡中打开操作

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

谢谢

小智 5

您可以使用 javascript 函数执行此操作

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


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

  • 伟大的。对于我们这些不太了解 MVC 的其他人来说,“aa”和“bb”是什么?你应该有类似 @Url.Action("Read", "MyController", new { id=@id}) 的东西。抱歉,这只是我的一个小问题,人们以为我们马上就知道了,而不是完成示例。 (2认同)