actionLink razor helper中的html"id"

Thi*_*ago 3 razor asp.net-mvc-3

我想指定的HTML idActionLink,但我不能这样做:

@html.ActionLink("Controller", "Action", new {@id = "tec"})
Run Code Online (Sandbox Code Playgroud)

因为这@id意味着参数tecid.

另一方面,如果我这样做

@html.ActionLink("Controller", "Action", new {@class = "tec"})
Run Code Online (Sandbox Code Playgroud)

结果将是:

<a href="Controller/Action" class="tec"></a>
Run Code Online (Sandbox Code Playgroud)

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

我想这个结果:

<a href="Controller/Action" id="tec"></a>
Run Code Online (Sandbox Code Playgroud)

Iri*_*dio 9

您还必须指定控制器,您可以删除@之前的ID

@Html.ActionLink("mylink", "Action", "Controller", new {id = "tec"})
Run Code Online (Sandbox Code Playgroud)

那是因为您使用的签名不是相对于HtmlAttributes的签名,而是路由值.如果您不想指定控制器,请使用此选项

@Html.ActionLink("mylink", "Action", null, new {id = "tec"})
Run Code Online (Sandbox Code Playgroud)