Html.ActionLink as a button or an image, not a link
Solution 1:
I like to use Url.Action() and Url.Content() like this:
<a href='@Url.Action("MyAction", "MyController")'>
<img src='@Url.Content("~/Content/Images/MyLinkImage.png")' />
</a>
Strictly speaking, the Url.Content is only needed for pathing is not really part of the answer to your question.
Thanks to @BrianLegg for pointing out that this should use the new Razor view syntax. Example has been updated accordingly.
Solution 2:
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 */
}
Solution 3:
Borrowing from Patrick's answer, I found that I had to do this:
<button onclick="location.href='@Url.Action("Index", "Users")';return false;">Cancel</button>
to avoid calling the form's post method.
Solution 4:
Call me simplistic, but I just do:
<a href="<%: Url.Action("ActionName", "ControllerName") %>">
<button>Button Text</button>
</a>
And you just take care of the hyperlink highlight. Our users love it :)
Solution 5:
Using bootstrap this is the shortest and cleanest approach to create a link to a controller action that appears as a dynamic button:
<a href='@Url.Action("Action", "Controller")' class="btn btn-primary">Click Me</a>
Or to use Html helpers:
@Html.ActionLink("Click Me", "Action", "Controller", new { @class = "btn btn-primary" })