asp.net-mvcactionlink

Html.ActionLink as a button or an image, not a link


In the latest (RC1) release of ASP.NET MVC, how do I get Html.ActionLink to render as a button or an image instead of a link?


Solution

  • Late response but you could just keep it simple and apply a CSS class to the htmlAttributes object.

    <%= Html.ActionLink("Button Name", "Index", null, new { @class="classname" }) %>
    

    and then create a class in your stylesheet

    a.classname
    {
        background: url(../Images/image.gif) no-repeat top left;
         display: block;
         width: 150px;
         height: 150px;
         text-indent: -9999px; /* hides the link text */
    }