C# 如何在新选项卡中打开剃须刀操作链接?
我试图在新选项卡中打开我的链接(必须是razor格式):C# 如何在新选项卡中打开剃须刀操作链接?,c#,html,razor,C#,Html,Razor,我试图在新选项卡中打开我的链接(必须是razor格式): 但这不起作用。有人知道怎么做吗?您正在将其设置为type为submit。这意味着浏览器应该将数据发布到服务器 事实上,标记没有类型属性 因此,远程键入属性,它应该适合您。只需使用HtmlHelper操作链接,并相应地设置路由值和HtmlAttributes @Html.ActionLink(Reports.RunReport, "RunReport", new { controller = "Performance", reportV
但这不起作用。有人知道怎么做吗?您正在将其设置为
type
为submit
。这意味着浏览器应该将
数据发布到服务器
事实上,标记没有类型属性
因此,远程
键入
属性,它应该适合您。只需使用HtmlHelper
操作链接
,并相应地设置路由值
和HtmlAttributes
@Html.ActionLink(Reports.RunReport, "RunReport", new { controller = "Performance", reportView = Model.ReportView.ToString() }, new { target = "_blank" })
看来你把我搞糊涂了。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(字符串、字符串、对象、对象)
不存在而无法编译
UrlHelper.Action
将仅基于您提供的操作生成URL,而不是
标记。如果要添加HtmlAttribute(如target=“\u blank”
,以在新选项卡中打开链接),您可以:
- 自己将目标属性添加到
元素中:
<a href="@Url.Action("RunReport", "Performance",
new { reportView = Model.ReportView.ToString() })",
target = "_blank" type="submit" id="runReport" class="button Secondary">
@Reports.RunReport
</a>
如果您的目标是使用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(linkText: "TestTab", actionName: "TestAction", controllerName: "TestController", routeValues: null, htmlAttributes: new { target = "_blank"})
asp.net mvc ActionLink带有角度参数的新选项卡
<a target="_blank" class="btn" data-ng-href="@Url.Action("RunReport", "Performance")?hotelCode={{hotel.code}}">Select Room</a>
用于
@Url.Action
您为什么要费心将其放入Url.Action
?只需输入
标记本身。虽然此代码可以回答问题,但提供有关此代码回答问题的原因和/或方式的附加上下文可提高其长期价值。
@Html.ActionLink(linkText: "TestTab", actionName: "TestAction", controllerName: "TestController", routeValues: null, htmlAttributes: new { target = "_blank"})
<a target="_blank" class="btn" data-ng-href="@Url.Action("RunReport", "Performance")?hotelCode={{hotel.code}}">Select Room</a>
<a href="@Url.Action("Action", "Controller")" target="_blank">Link Text</a>
@Html.ActionLink(
"Pay Now",
"Add",
"Payment",
new { @id = 1 },htmlAttributes:new { @class="btn btn-success",@target= "_blank" } )