如何在新选项卡中打开剃须刀操作链接
本文关键字:剃须刀 链接 操作 新选项 选项 | 更新日期: 2023-09-27 18:36:05
我试图让我的链接在新选项卡中打开(它必须是剃刀格式):
<a href="@Url.Action("RunReport", "Performance", new { reportView = Model.ReportView.ToString() }, new { target = "_blank" })" type="submit" id="runReport" class="button Secondary">@Reports.RunReport</a>
不过这是行不通的。 有人知道如何做到这一点吗?
只需使用HtmlHelper
ActionLink
并相应地设置RouteValues
和HtmlAttributes
即可。
@Html.ActionLink(Reports.RunReport, "RunReport", new { controller = "Performance", reportView = Model.ReportView.ToString() }, new { target = "_blank" })
看起来你混淆了 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>
不会编译,因为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" })
的目标是使用 ActionLink 帮助程序并打开一个新选项卡:
@Html.ActionLink("New tab please", "Home", null , new { target = "_blank" })
@Html.ActionLink("New tab please", "Home", Nothing, New With {Key .target = "_blank"})
@Html.ActionLink(
"Pay Now",
"Add",
"Payment",
new { @id = 1 },htmlAttributes:new { @class="btn btn-success",@target= "_blank" } )
for
@Url.行动
<a href="@Url.Action("Action", "Controller")" target="_blank">Link Text</a>
使用命名参数:
@Html.ActionLink(linkText: "TestTab", actionName: "TestAction", controllerName: "TestController", routeValues: null, htmlAttributes: new { target = "_blank"})
asp.net mvc 动作链接 带有角度参数的新选项卡
<a target="_blank" class="btn" data-ng-href="@Url.Action("RunReport", "Performance")?hotelCode={{hotel.code}}">Select Room</a>
您正在将其设置为type
submit
。这意味着浏览器应该将您的<form>
数据发布到服务器。
事实上,根据 w3schools ,标签没有类型属性。
所以远程type
属性,它应该适合你。
> <a href="@Url.Action("RunReport", "Performance", new { reportView = Model.ReportView.ToString() })" type="submit" id="runReport" target="_blank" class="button Secondary"> @Reports.RunReport </a>