Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 添加目标="_“空白”;在指定routename时发送到RouteLink_C#_Asp.net Mvc - Fatal编程技术网

C# 添加目标="_“空白”;在指定routename时发送到RouteLink

C# 添加目标="_“空白”;在指定routename时发送到RouteLink,c#,asp.net-mvc,C#,Asp.net Mvc,我似乎找不到下面问题的答案 我试图使用带有target=“\u blank”属性的方法 我尝试了以下方法,但没有得到预期的输出 @Html.RouteLink("Display text","My_Route_Name",new{Id="AGuid", target="_blank"} 实际产出 <a href="/my_route_url/AGuid?target=_blank">Display text</a> <a href="/my_route_url/

我似乎找不到下面问题的答案

我试图使用带有
target=“\u blank”
属性的方法

我尝试了以下方法,但没有得到预期的输出

@Html.RouteLink("Display text","My_Route_Name",new{Id="AGuid", target="_blank"}
实际产出

<a href="/my_route_url/AGuid?target=_blank">Display text</a>
<a href="/my_route_url/AGuid" target="_blank">Display text</a>

预期产出

<a href="/my_route_url/AGuid?target=_blank">Display text</a>
<a href="/my_route_url/AGuid" target="_blank">Display text</a>

有什么想法和建议吗


ps.堆栈溢出上的搜索没有显示任何结果。

尝试使用
htmlAttributes:
并指定
null
作为第三个参数值,因为在第三个参数上它指的是
对象路由值
,而不是
对象htmlAttributes

参数

public static MvcHtmlString RouteLink(
    this HtmlHelper htmlHelper,
    string linkText,
    Object routeValues, //this is getting targeted in your case
    Object htmlAttributes
)
@Html.RouteLink("Display text","My_Route_Name",new { Id = "AGuid" }, htmlAttributes: new {target="_blank"})
更改

public static MvcHtmlString RouteLink(
    this HtmlHelper htmlHelper,
    string linkText,
    Object routeValues, //this is getting targeted in your case
    Object htmlAttributes
)
@Html.RouteLink("Display text","My_Route_Name",new { Id = "AGuid" }, htmlAttributes: new {target="_blank"})


尝试使用
htmlAttributes:
并指定
null
作为第三个参数值,因为在第三个参数上它指的是
对象路由值
,而不是
对象htmlAttributes

参数

public static MvcHtmlString RouteLink(
    this HtmlHelper htmlHelper,
    string linkText,
    Object routeValues, //this is getting targeted in your case
    Object htmlAttributes
)
@Html.RouteLink("Display text","My_Route_Name",new { Id = "AGuid" }, htmlAttributes: new {target="_blank"})
更改

public static MvcHtmlString RouteLink(
    this HtmlHelper htmlHelper,
    string linkText,
    Object routeValues, //this is getting targeted in your case
    Object htmlAttributes
)
@Html.RouteLink("Display text","My_Route_Name",new { Id = "AGuid" }, htmlAttributes: new {target="_blank"})


您可以像下面这样使用

@Html.RouteLink("Display text", "My_Route_Name", new { Id = "AGuid" }, new { target = "_blank" });

你可以像下面这样使用

@Html.RouteLink("Display text", "My_Route_Name", new { Id = "AGuid" }, new { target = "_blank" });

+1.把我定位在正确的方向。我使用了普拉格尼什·哈拉什建议的解决方案。id必须进入RouteValue,目标必须进入htmlAttributes(我的首选项)。我相信你的解决方案也会起作用。那么我相信@PragneshKhalas是有效的,因为我的印象是
id
与元素
id
相关,而不是使它适合
路线值
。无论如何。我会更新相同的,但是你可以标记他的答案..啊,不,这里提到的id不是html属性,而是一个对象id,就像来自数据库的guid。愚蠢的我不能把2个答案作为一个解决方案,因为你应得的话,那么:-没有任何好友好友…感谢你的好意……)我只是糊涂了。快乐编码…)+1.把我定位在正确的方向。我使用了普拉格尼什·哈拉什建议的解决方案。id必须进入RouteValue,目标必须进入htmlAttributes(我的首选项)。我相信你的解决方案也会起作用。那么我相信@PragneshKhalas是有效的,因为我的印象是
id
与元素
id
相关,而不是使它适合
路线值
。无论如何。我会更新相同的,但是你可以标记他的答案..啊,不,这里提到的id不是html属性,而是一个对象id,就像来自数据库的guid。愚蠢的我不能把2个答案作为一个解决方案,因为你应得的话,那么:-没有任何好友好友…感谢你的好意……)我只是糊涂了。快乐编码…)这就是我使用的解决方案。谢谢这是我用过的解决办法。谢谢