Thi*_*ago 3 razor asp.net-mvc-3
我想指定的HTML id中ActionLink,但我不能这样做:
@html.ActionLink("Controller", "Action", new {@id = "tec"})
Run Code Online (Sandbox Code Playgroud)
因为这@id意味着参数tec值id.
另一方面,如果我这样做
@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)
您还必须指定控制器,您可以删除@之前的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)
| 归档时间: |
|
| 查看次数: |
8371 次 |
| 最近记录: |