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:
@Html.ActionLink("About", "Index", "about", null, new {@class = aboutLinkClass})
You're passing the string literal "@aboutLinkClass" when you actually want to pass your String object called aboutLinkClass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With