I’d like to give the like generated with an Html.ActionLink an HTML id so I can change the CSS depending on where I am. I have a MasterPage with a set of links and I’d like to distinguish the active “Tab” with Jquery changing the css of that active #id
Right now I’m using:
<%: Html.ActionLink("Some View", "Index", "controller")%>
It generates:
<a href="/controller">Some View</a>
I’d like to generate:
<a id="something" href="/controller">Some View</a>
Is that possible? I’ve tried:
<%: Html.ActionLink("Some View", "Index", "controller", new {id="blahbla")%>
But that generates:
<a href="/controller/Length?5">Some View</a>
You were on the right track. I am not sure why it didn’t work for you as your code has a typo which would have produced a
} expectederror. The following is what you are looking for:Which produces teh following HTML:
Edit: I just realized what the issue is because I was mis-reading what you tried. You are using the wrong overload to pass in the
idhtml element. Your probably passing thenew { id="blah" }param into therouteValuesparameter, which will cause it to be used when building the route link, rather than thehtmlAttributesparamater which is what you want.I think you are using:
When what you need to use is the following overload like I did above in my answer:
Which makes sure
new { id="blah" }is being passed into thehtmlAttributesparam.