ASP.Net MVC - How do I apply a CSS class to html.ActionLink in MVC?

By [)ia6l0 iii

Use the ActionLink overloaded method that takes the html attributes that would be applied to the generated link.

For e.g, the following code will add the css class called "className" to the link that is generated.
@Html.ActionLink(item.FirstName, "MyView", "MyModel", new { id = item.ID }, new { @class = "className" })

Remember to prefix the class keyword with the @ symbol, as Class is a reserverd word.

Related FAQs

If you browse your mvc pages, through modern day browsers like Chrome - you will find that there would be additional requests like the ones to the favicon. This is the icon, that appears to the left of the web address in the browser once the page loads.
ASP.Net 4.0 provides the SetSessionStateBehavior method through the HTTPContext Class.
Use the Override versions of the page methods instead of thedefault page methods. This would ensure that the .Net runtime does not have to invoke delegates.
Use the FilePathResult to return a file content as the http response.
Use the "UrlReferrer" property of the Request object to retrieve the previous page url.
You can check the contenttype of the request, and figure out if the request is an JSon request
ASP.Net MVC - How do I apply a CSS class to html.ActionLink in MVC?  (2544 Views)