我想在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>
最佳答案
您还必须指定 Controller ,您可以在 id 之前删除 @
@Html.ActionLink("mylink", "Action", "Controller", new {id = "tec"})
这是因为您使用的签名不是与 HtmlAttributes 相关的签名,而是与路由值相关的签名。如果不想指定 Controller ,就用这个
@Html.ActionLink("mylink", "Action", null, new {id = "tec"})
关于asp.net-mvc-3 - html "id"in actionLink Razor 助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7489352/