title: Why is Extension Method Not Found in MVC4 Razor View?
body: <p>Given the following string extension method </p>
  
  <pre><code>namespace JHS.ExtensionMethods
  {
    public static class StringExtensions
    {
      public static string ToUSAPhone(this String str)
      {
        return String.Format("{0:(###) ###-####}", Double.Parse(str));
      }
    }
  }
  </code></pre>
  
  <p>A @using statement was added to the MVC4 Razor view</p>
  
  <pre><code>@using JHS.ExtensionMethods;
  </code></pre>
  
  <p>and the following string value calls the extension method</p>
  
  <pre><code>@Model.producer.phone.ToUSAPhone()
  </code></pre>
  
  <p>which results in the following error</p>
  
  <pre><code>'string' does not contain a definition for 'ToUSAPhone'
  </code></pre>
  
  <p>I also tried putting the namespace in the web.config of the /Views folder and receive the same error.</p>
  
  <pre><code>&lt;pages pageBaseType="System.Web.Mvc.WebViewPage"&gt;
    &lt;namespaces&gt;
      &lt;add namespace="System.Web.Mvc" /&gt;
      &lt;add namespace="System.Web.Mvc.Ajax" /&gt;
      &lt;add namespace="System.Web.Mvc.Html" /&gt;
      &lt;add namespace="System.Web.Optimization"/&gt;
      &lt;add namespace="System.Web.Routing" /&gt;
      &lt;add namespace="JHS.ExtensionMethods"/&gt;
    &lt;/namespaces&gt;
  &lt;/pages&gt;
  </code></pre>
  
  <p>I have verified the extension method works by putting the same call in a C# class</p>
  
  <pre><code>string test=producer.phone.ToUSAPhone();
  </code></pre>
  
  <p>It seems the reference to the extension method is not available in the MVC4 Razor view but I can't figure out why?</p>