2

In ASP.NET MVC view helper, you can do something like

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

which will produce the following HTML

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

My question is.... what if I want to set the "class" attribute?

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

That won't compile because "class" is a reserved word.

Is there a work-around?

Adam
  • 913
  • 8
  • 12

1 Answers1

12

Yes, using the @ literal:

<%= Html.ActionLink("click me", "DoSomething", null, 
    new { @class = "a-class-name" } )  %>
Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928