Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I took the above answers and made a bit of a wrapper extension:</p> <pre><code> public static MvcHtmlString ActionImageLink(this HtmlHelper helper, string src, string altText, UrlHelper url, string actionName, string controllerName) { return ActionImageLink(helper, src, altText, url, actionName, controllerName, null, null); } public static MvcHtmlString ActionImageLink(this HtmlHelper helper, string src, string altText, UrlHelper url, string actionName, string controllerName, Dictionary&lt;string, string&gt; linkAttributes, Dictionary&lt;string, string&gt; imageAttributes) { return ActionImageLink(helper, src, altText, url, actionName, controllerName, null, linkAttributes, imageAttributes); } public static MvcHtmlString ActionImageLink(this HtmlHelper helper, string src, string altText, UrlHelper url, string actionName, string controllerName, dynamic routeValues, Dictionary&lt;string, string&gt; linkAttributes, Dictionary&lt;string, string&gt; imageAttributes) { var linkBuilder = new TagBuilder("a"); linkBuilder.MergeAttribute("href", routeValues == null ? url.Action(actionName, controllerName) : url.Action(actionName, controllerName, routeValues)); var imageBuilder = new TagBuilder("img"); imageBuilder.MergeAttribute("src", url.Content(src)); imageBuilder.MergeAttribute("alt", altText); if (linkAttributes != null) { foreach (KeyValuePair&lt;string, string&gt; attribute in linkAttributes) { if (!string.IsNullOrWhiteSpace(attribute.Key) &amp;&amp; !string.IsNullOrWhiteSpace(attribute.Value)) { linkBuilder.MergeAttribute(attribute.Key, attribute.Value); } } } if (imageAttributes != null) { foreach (KeyValuePair&lt;string, string&gt; attribute in imageAttributes) { if (!string.IsNullOrWhiteSpace(attribute.Key) &amp;&amp; !string.IsNullOrWhiteSpace(attribute.Value)) { imageBuilder.MergeAttribute(attribute.Key, attribute.Value); } } } linkBuilder.InnerHtml = MvcHtmlString.Create(imageBuilder.ToString(TagRenderMode.SelfClosing)).ToString(); return MvcHtmlString.Create(linkBuilder.ToString()); } </code></pre> <p>has made it easier for me anyway, hope it helps someone else.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload