我试图让我的链接在新标签中打开(它必须是剃刀格式):
<a href="@Url.Action("RunReport", "Performance", new { reportView = Model.ReportView.ToString() }, new { target = "_blank" })" type="submit" id="runReport" class="button Secondary">@Reports.RunReport</a>
Run Code Online (Sandbox Code Playgroud)
这不行.有人知道怎么做吗?
Gab*_*abe 117
只需使用HtmlHelper
ActionLink
和设置RouteValues
,并HtmlAttributes
相应地.
@Html.ActionLink(Reports.RunReport, "RunReport", new { controller = "Performance", reportView = Model.ReportView.ToString() }, new { target = "_blank" })
Run Code Online (Sandbox Code Playgroud)
Eri*_*ips 38
看起来你混淆了Url.Action()的Html.ActionLink ().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>
Run Code Online (Sandbox Code Playgroud)
WDR*_*ust 20
因为UrlHelper.Action(string,string,object,object)
不存在,所以不会编译.
UrlHelper.Action
只会根据您提供的操作生成Urls,而不是<a>
标记.如果要添加HtmlAttribute(例如target="_blank"
,要在新选项卡中打开链接),您可以:
<a>
自己将target属性添加到元素:
<a href="@Url.Action("RunReport", "Performance",
new { reportView = Model.ReportView.ToString() })",
target = "_blank" type="submit" id="runReport" class="button Secondary">
@Reports.RunReport
</a>
Run Code Online (Sandbox Code Playgroud)使用Html.ActionLink生成<a>
标记元素:
@Html.ActionLink("Report View", "RunReport", null, new { target = "_blank" })
Run Code Online (Sandbox Code Playgroud)Jos*_*980 17
如果您的目标是使用ActionLink帮助程序并打开一个新选项卡:
@Html.ActionLink("New tab please", "Home", null , new { target = "_blank" })
@Html.ActionLink("New tab please", "Home", Nothing, New With {Key .target = "_blank"})
Run Code Online (Sandbox Code Playgroud)
小智 9
@Html.ActionLink(
"Pay Now",
"Add",
"Payment",
new { @id = 1 },htmlAttributes:new { @class="btn btn-success",@target= "_blank" } )
Run Code Online (Sandbox Code Playgroud)
为了
@Url.Action
<a href="@Url.Action("Action", "Controller")" target="_blank">Link Text</a>
Run Code Online (Sandbox Code Playgroud)
具有命名参数:
@Html.ActionLink(linkText: "TestTab", actionName: "TestAction", controllerName: "TestController", routeValues: null, htmlAttributes: new { target = "_blank"})
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
104261 次 |
最近记录: |