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
There are many threads on the internet that tell you to play with Session or any other web.config values to get Global.asax events working. If they do not work, then this tip is for you.
To stop a robot from visiting your website and causing undesirable robot traffic and many other problems, follow one of the below said three ways:
One of the best ways is to use the RouteConstraint to validate the route values and then choose a route to controller. Route values that hold values of integer is the best example. If the route value is passed as string which cannot be converted to an Integer, we suffer with run-time and unhandled exceptions on our code.
Use Page.ClientQueryString to get the encoded query string portion of the requested url.
Use Page.MaintainScrollPositionOnPostBack to retain the scroll position after a postback.
You can set it as a page directive:
Use the FileContentResult as the ActionResult to send byte array as http response.
ASP.Net MVC - How do I apply a CSS class to html.ActionLink in MVC? (615 Views)