Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use CSS on an Html.ActionLink in C#

I tried this code

<%: Html.ActionLink("Home", "Index", "Home", new { @class = "NavLink" })%>

and it links to the css so that I can style the link, but it changes the link to have a different URL that is not to my controller like it is without the new { @class = "NavLink" }. Is there any way to let me style these links without ruining my URLs so they go to the correct pages?

Thanks!

like image 903
pongahead Avatar asked Mar 03 '11 18:03

pongahead


1 Answers

Make sure you are using the proper overload:

<%: Html.ActionLink("Home", "Index", "Home", null, new { @class = "NavLink" })%>
                                              ^                ^
                                          routeValues    htmlAttributes
like image 58
Darin Dimitrov Avatar answered Sep 21 '22 13:09

Darin Dimitrov