title: How to create an ActionImage from a CSS Sprite
body: <p>This is a follow up on my previous question: <a href="https://stackoverflow.com/questions/8948955/how-do-you-map-areas-on-icon-set-to-buttons">How do you map areas on icon set to buttons?</a></p>
  
  <p>I decided to make my own <code>HtmlHelper</code> extension in order to create an <code>ActionImage</code> link, so I cannibalized some of the popular extensions posted on SO and got this:</p>
  
  <pre><code>// Controller/Action Image Link
  public static MvcHtmlString ActionImage(this HtmlHelper html, 
      string controller, string action, object routeValues, 
      string imageSrc, string alternateText, object imageAttributes)
  {
      UrlHelper url = new UrlHelper(html.ViewContext.RequestContext);
  
      // build the &lt;img&gt; tag
      TagBuilder imgBuilder = new TagBuilder("img");
      imgBuilder.MergeAttribute("src", url.Content(imageSrc));
      imgBuilder.MergeAttribute("alternateText", alternateText);
      string imgHtml = imgBuilder.ToString(TagRenderMode.SelfClosing);
  
      // build the &lt;a&gt; tag
      TagBuilder anchorBuilder = new TagBuilder("a");
      anchorBuilder.MergeAttribute("href", url.Action(action, controller, routeValues));
      anchorBuilder.InnerHtml = imgHtml; // include the &lt;img&gt; tag inside
      string anchorHtml = anchorBuilder.ToString(TagRenderMode.Normal);
  
      return MvcHtmlString.Create(anchorHtml);
  }
  </code></pre>
  
  <p>Now, the problem is that I have a CSS Sprite with and I don't know how to make it work with the <code>ActionImage</code> extension method:</p>
  
  <pre><code>@Html.ActionImage("Account", "LogOn", null, Sprite.Image("~/App_Sprites/twitterlogin.png"), "", null)
  </code></pre>
  
  <p>I tried calling the <code>ToString()</code> method of the sprite, but it doesn't return the URL. Is there another way to make this happen?</p>