如何在新标签中打开AA剃刀动作链接?(How to have a a razor action li

2019-06-25 01:55发布

我试图让我的链接在新标签中(它必须在剃刀格式)打开:

    <a href="@Url.Action("RunReport", "Performance", new { reportView = Model.ReportView.ToString() }, new { target = "_blank" })" type="submit" id="runReport" class="button Secondary">@Reports.RunReport</a>

这不,虽然工作。 有人知道怎么做吗?

Answer 1:

看起来你是在混淆Html.ActionLink()用于Url.Action() 。 Url.Action没有参数来设定目标,因为它只返回一个URL。

根据您当前的代码,锚或许应该是这样的:

<a href="@Url.Action("RunReport", "Performance", new { reportView = Model.ReportView.ToString() })" 
   type="submit" 
   id="runReport" 
   target="_blank"
   class="button Secondary">
     @Reports.RunReport
</a>


Answer 2:

只需使用HtmlHelper ActionLink并设置RouteValuesHtmlAttributes相应。

@Html.ActionLink(Reports.RunReport, "RunReport", new { controller = "Performance", reportView = Model.ReportView.ToString() }, new { target = "_blank" })


Answer 3:

这不会编译因为UrlHelper.Action(string,string,object,object)不存在。

UrlHelper.Action只将根据您提供的行动,而不是生成URL <a>标记。 如果你想添加一个HtmlAttribute(如target="_blank" ,以打开新的标签页链接),您可以:

  • 目标属性添加到<a>自己的元素:

     <a href="@Url.Action("RunReport", "Performance", new { reportView = Model.ReportView.ToString() })", target = "_blank" type="submit" id="runReport" class="button Secondary"> @Reports.RunReport </a> 
  • 使用Html.ActionLink生成<a>标记元素:

     @Html.ActionLink("Report View", "RunReport", null, new { target = "_blank" }) 


Answer 4:

如果你的目标是使用ActionLink的助手并打开一个新的标签:

@Html.ActionLink("New tab please", "Home", null , new { target = "_blank" })

@Html.ActionLink("New tab please", "Home", Nothing, New With {Key .target = "_blank"})


Answer 5:

使用参数名:

@Html.ActionLink(linkText: "TestTab", actionName: "TestAction", controllerName: "TestController", routeValues: null, htmlAttributes: new { target = "_blank"})


Answer 6:

对于

@ Url.Action

<a href="@Url.Action("Action", "Controller")" target="_blank">Link Text</a>


Answer 7:

具有角参数asp.net MVC ActionLink的新标签

<a  target="_blank" class="btn" data-ng-href="@Url.Action("RunReport", "Performance")?hotelCode={{hotel.code}}">Select Room</a>


Answer 8:

@Html.ActionLink(
"Pay Now",
"Add",
"Payment",
new { @id = 1 },htmlAttributes:new { @class="btn btn-success",@target= "_blank" } )


Answer 9:

要设置it't typesubmit 。 这意味着浏览器应该发表您<form>数据发送到服务器。

事实上标签根据没有类型属性W3Schools的 。

因此,远程type属性,它应该为你工作。



Answer 10:

<a href="@Url.Action("RunReport", "Performance", new { reportView = Model.ReportView.ToString() })" type="submit" id="runReport" target="_blank" class="button Secondary"> @Reports.RunReport </a>



文章来源: How to have a a razor action link open in a new tab?
标签: c# html razor