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!
Make sure you are using the proper overload:
<%: Html.ActionLink("Home", "Index", "Home", null, new { @class = "NavLink" })%>
^ ^
routeValues htmlAttributes
Method Actionlink have some overloading.
If you want to determine some html attributes, you should use such methods(in your case):
ActionLink(HtmlHelper, String, String, RouteValueDictionary, IDictionary<String, Object>)
ActionLink(HtmlHelper, String, String, String, Object, Object)
ActionLink(HtmlHelper, String, String, String, RouteValueDictionary, IDictionary<String, Object>)
More about this here: http://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions.actionlink.aspx
来源:https://stackoverflow.com/questions/5184976/how-to-use-css-on-an-html-actionlink-in-c-sharp