title: MVC3 razor helper method to display email address with mailto passing variables
body: <p>I'm trying to get a mailto link to display with the persons name rather than the actual email address.</p>
  
  <p>In my <code>details.cshtml</code> file I have the page strongly typed to my Supplier </p>
  
  <pre><code>@model TheWorkshop.Web.Models.Supplier
  </code></pre>
  
  <p>but although I can use </p>
  
  <pre><code>@Html.DisplayFor(model =&gt; model.Email)
  </code></pre>
  
  <p>to display a mailto link with the text value the same as the mailto e.g.  </p>
  
  <blockquote>
    <p>&lt; a href="mailto: me@blah.com">me@blah.com&lt; /a></p>
  </blockquote>
  
  <p>What I want is to display the name of the person instead. So after hunting about I decided to try to make a Helper method</p>
  
  <pre><code>public static MvcHtmlString PrettyEmailAddress(this HtmlHelper htmlHelper, 
                                                 string email, string name)
  {
      var mailToLink = new TagBuilder("a");
      mailToLink.Attributes.Add("mailto", email);
      mailToLink.SetInnerText(name);
  
      return MvcHtmlString.Create(mailToLink.ToString());
  }
  </code></pre>
  
  <p>but the trouble is that when I try to call it in the binding like this:</p>
  
  <pre><code> @Html.PrettyEmailAddress(@model.Email, @model.Name))
  </code></pre>
  
  <p>I get a compilation error</p>
  
  <blockquote>
    <p>CS0103: The name 'model' does not exist in the current context</p>
  </blockquote>
  
  <p>If I pass strings instead of the <code>@model.Email</code> and '@model.Name` then the helper works fine, but how do I pass variables into the helper?</p>