I have variable for a CSS class value that is assigned to variable in a view:
string aboutLinkClass = "normalLink";
This can change based on context. Later in the view I call Html.ActionLink and I need to use that variable, but the following fails to produce the desired output:
@Html.ActionLink("About", "Index", "about", null, new {@class="@aboutLinkClass"})
It treats @aboutLinkClass as static text. so it produces:
<a class="@aboutLinkClass" href="/about">About</a>
Instead I want it to produce:
<a class="normalLink" href="/about">About</a>
What is the syntax I need to use to pass it correctly?
Try this:
You’re passing the string literal
"@aboutLinkClass"when you actually want to pass yourStringobject calledaboutLinkClass.