我试图在新标签页中打开我的链接(它必须是剃刀格式):
<a href="@Url.Action("RunReport", "Performance", new { reportView = Model.ReportView.ToString() }, new { target = "_blank" })" type="submit" id="runReport" class="button Secondary">@Reports.RunReport</a>
这不行。有谁知道怎么做?
答案 0 :(得分:111)
只需使用HtmlHelper
ActionLink
并相应地设置RouteValues
和HtmlAttributes
。
@Html.ActionLink(Reports.RunReport, "RunReport", new { controller = "Performance", reportView = Model.ReportView.ToString() }, new { target = "_blank" })
答案 1 :(得分:34)
您似乎对Html.ActionLink() Url.Action()感到困惑。 Url.Action没有用于设置Target的参数,因为它只返回一个URL。
根据您当前的代码,锚点应该如下所示:
<a href="@Url.Action("RunReport", "Performance", new { reportView = Model.ReportView.ToString() })"
type="submit"
id="runReport"
target="_blank"
class="button Secondary">
@Reports.RunReport
</a>
答案 2 :(得分:20)
由于UrlHelper.Action(string,string,object,object)
不存在,因此无法编译。
UrlHelper.Action
只会根据您提供的操作生成网址,而不是<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" })
答案 3 :(得分:17)
如果您的目标是使用ActionLink帮助程序并打开一个新选项卡:
@Html.ActionLink("New tab please", "Home", null , new { target = "_blank" })
@Html.ActionLink("New tab please", "Home", Nothing, New With {Key .target = "_blank"})
答案 4 :(得分:3)
使用命名参数:
@Html.ActionLink(linkText: "TestTab", actionName: "TestAction", controllerName: "TestController", routeValues: null, htmlAttributes: new { target = "_blank"})
答案 5 :(得分:2)
对于
@ Url.Action
pngcrush
答案 6 :(得分:1)
带有角度参数的asp.net mvc ActionLink新选项卡
<a target="_blank" class="btn" data-ng-href="@Url.Action("RunReport", "Performance")?hotelCode={{hotel.code}}">Select Room</a>
答案 7 :(得分:1)
@Html.ActionLink(
"Pay Now",
"Add",
"Payment",
new { @id = 1 },htmlAttributes:new { @class="btn btn-success",@target= "_blank" } )
答案 8 :(得分:0)
答案 9 :(得分:0)
<a href="@Url.Action("RunReport", "Performance", new { reportView = Model.ReportView.ToString() })" type="submit" id="runReport" target="_blank" class="button Secondary"> @Reports.RunReport </a>