Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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
Asp.net mvc 3 html";id";in-actionLink剃须刀助手_Asp.net Mvc 3_Razor - Fatal编程技术网

Asp.net mvc 3 html";id";in-actionLink剃须刀助手

Asp.net mvc 3 html";id";in-actionLink剃须刀助手,asp.net-mvc-3,razor,Asp.net Mvc 3,Razor,我想在ActionLink中指定htmlid,但我不能这样做: @html.ActionLink("Controller", "Action", new {@id = "tec"}) 因为@id意味着tec是id参数的值 另一方面,如果我这样做 @html.ActionLink("Controller", "Action", new {@class = "tec"}) 结果将是: <a href="Controller/Action" class="tec"></a>

我想在
ActionLink
中指定html
id
,但我不能这样做:

@html.ActionLink("Controller", "Action", new {@id = "tec"})
因为
@id
意味着
tec
id
参数的值

另一方面,如果我这样做

@html.ActionLink("Controller", "Action", new {@class = "tec"})
结果将是:

<a href="Controller/Action" class="tec"></a>

您知道一种指定html id的方法吗

我想要这个结果:

<a href="Controller/Action" id="tec"></a>

您还必须指定控制器,并且可以在id之前删除
@

@Html.ActionLink("mylink", "Action", "Controller", new {id = "tec"})
这是因为您使用的签名不是与HtmlAttributes相关的签名,而是与路由值相关的签名。如果不想指定控制器,请使用此选项

@Html.ActionLink("mylink", "Action", null, new {id = "tec"})

您案例中的方法签名应该是这样的

   public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    Object routeValues,
    Object htmlAttributes
)

以相同的格式提供参数。htmlattributes应该用于创建新的html对象。

太好了!我在文本链接中留下一个空白以显示一个图像作为链接:@Html.Action(“,Action,“Controller”,null,new{id=“tec”})。它解决了我的问题!Tks!