2

在 ASP.NET MVC 视图助手中,您可以执行类似的操作

<%= Html.ActionLink("click me", "DoSomething", null, new { someAttribute = "a value" } )  %>

这将产生以下 HTML

<a href="DoSomething" someAttribute="a value">click me</a>

我的问题是....如果我想设置“类”属性怎么办?

<%= Html.ActionLink("click me", "DoSomething", null, new { class = "a-class-name" } )  %>

这不会编译,因为“类”是保留字。

有解决办法吗?

4

1 回答 1

12

是的,使用@ 文字

<%= Html.ActionLink("click me", "DoSomething", null, 
    new { @class = "a-class-name" } )  %>
于 2009-10-20T15:10:17.867 回答