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?

1 Answer 1

12

Yes, using the @ literal:

<%= Html.ActionLink("click me", "DoSomething", null, 
    new { @class = "a-class-name" } )  %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.