TwitterFacebookGoogle

Rendering Icons as links in ASP .NET MVC

Modifying the behaviors of HTML helper methods such as ActionLink is a pain and requires quite a bit of code. Sometimes, however, you get lucky and are able to avoid it. What follows is once such case.

Here is one quick way that you can use to render an icon as a link in ASP .NET MVC.

First, create a CSS style for the icon:

 .print-icon {
    background: url("/assets/print-icon.png");
 }

Next, use it when generating the link:

  @Html.ActionLink(" ", "Action", new { id = /* blah */ }, new { @class = "print-icon" }

And, that does it!

Cheers!

Twitter Email Linkedin Digg Stumbleupon Subscribe

Leave a comment

Your email address will not be published.


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

CyberChimps