views:

229

answers:

1

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?

+11  A: 

Yes, using the @ literal:

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