好的,我找不到答案:
<%: Html.ActionLink("Click Here", "Action", null, new {class="myClass"})%>
我想设置生成的元素的CSS类属性。
显然,C#不允许我使用“class”作为对象成员的名字。
我该怎么办?
你能尝试用以下方法逃避课程:@。
因此,请将您的代码修改为:
<%: Html.ActionLink("Click Here", "Action", null, new {@class="myClass"})%>
在this answer to a similar question中使用Class中的大写'C'也有效。属性名称将转换为小写。
<%: Html.ActionLink("Click Here", "Action", null, new { Class = "myClass" })%>