When creating a link to a controller action in ASP.NET MVC, using the generic
ActionLink
method is preferable, because it allows for strongly typed links that are refactoring friendly.
Default:
ActionLink
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
However, what if we want to have an image that links to an action? You might think that you could combine the
ActionLink
and
Image
and
Button
helpers like this:
Using Button
<input type="button" title="Delete" value="D" onclick="location.href='@Url.Action("Delete", "movies", new { id = item.ID })'" />
Using Image
<a href="@Url.Action("Delete", "movies", new { id = item.ID })" title="Edit">
<img src="../../Content/Images/Delete.png" />
</a>
Thanks,
Imdadhusen