Passing css class name to asp.mvc view helper

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

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

      

which produces 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" } )  %>

      

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

Is there a job?

+2


source to share


1 answer


Yes, using @literal :



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

      

+12


source







All Articles