Use a "class" (or other reserved keyword) as a property for an anonymous type

Well, I can not find the answer to this question:

<%: Html.ActionLink("Click Here", "Action", null, new {class="myClass"})%>

I want to set the CSS class attribute of the generated element.

Obviously, C # will not allow me to use the "class" as the name of a member of an object.

What should I do?

+5
source share
1 answer

Can you try to exit the class with: @.

So, please change your code to:

<%: Html.ActionLink("Click Here", "Action", null, new {@class="myClass"})%>
+12
source

All Articles