passing css class name to asp.mvc view helper

1.4k Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, using the @ literal:

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