how to make html.actionlink without text but with image inside
Here is a solution.
<a href="<%= Url.RouteUrl("MyRoute", new { id = Model.Id }) %>">
<img src="myimage.png" alt="My Image" />.
</a>
Essentially, ActionLink is for text links and there isn't an equivalent for images, but you can use Url.RouteUrl to get the address for the link and put any HTML code you like inside of the anchor (W3C permitting of course).
This way is easiest (using Razor):
<a href="@Url.Action("Action", "Controller", new { lang = "de", returnUrl = this.Request.RawUrl }, new { @style = "background-image: url(/Images/Company/de.png)", @class = "languageLink" })"><img src="myimage.png" alt="My Image" /></a>
based on a previous SO question (that was closed), here's a solution:
public static string ImageLink(this HtmlHelper htmlHelper,
string imgSrc, string alt,
string actionName, string controllerName, object routeValues,
object htmlAttributes, object imgHtmlAttributes)
{
UrlHelper urlHelper = ((Controller)htmlHelper.ViewContext.Controller).Url;
string imgtag = htmlHelper.Image(imgSrc, alt, imgHtmlAttributes);
string url = urlHelper.Action(actionName, controllerName, routeValues);
TagBuilder imglink = new TagBuilder("a");
imglink.MergeAttribute("href", url);
imglink.InnerHtml = imgtag;
imglink.MergeAttributes(new RouteValueDictionary(htmlAttributes), true);
return imglink.ToString();
}
the orignal can be found here: Is there an ASP.NET MVC HtmlHelper for image links?