title: MVC extension unrecognized
body: <p>I am building a side menu page wuth the following code</p>
  
  <pre><code>&lt;nav class="navbar-default navbar-static-side" role="navigation"&gt;
      &lt;div class="sidebar-collapse"&gt;
          &lt;ul class="nav" id="side-menu"&gt;
              @if ( User.IsInRole( Constants.ROLE_ADMIN ) ) {
                  &lt;li class="@Html.IsSelected(controller: "UserGroup")"&gt;
                      &lt;a href="@Url.Action("Index", "UserGroup")"&gt;&lt;i class="fa fa-user"&gt;&lt;/i&gt; &lt;span class="nav-label"&gt;Users and Roles&lt;/span&gt; &lt;span class="fa arrow"&gt;&lt;/span&gt;&lt;/a&gt;
                      &lt;ul class="nav nav-second-level"&gt;
                          &lt;li class="@Html.IsSelected(action: "Index")"&gt;&lt;a href="@Url.Action("Index", "UserGroup")"&gt;Users&lt;/a&gt;&lt;/li&gt;
                          &lt;li class="@Html.IsSelected(action: "CreateUser")"&gt;&lt;a href="@Url.Action("CreateUser", "UserGroup")"&gt;Create user&lt;/a&gt;&lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/li&gt;
              }
          &lt;/ul&gt;
      &lt;/div&gt;
  &lt;/nav&gt;
  </code></pre>
  
  <p>The <code>Html.IsSelected</code> extension method simply add a css class to the item to set as selected by looking at the controller and/or action</p>
  
  <pre><code>namespace MyWebApp.Helpers
  {
      public static class BootstrapExtensions
      {
          public static string IsSelected( this HtmlHelper html, string controller = null, string action = null ) {
              string cssClass = "active";
              string currentAction = (string)html.ViewContext.RouteData.Values["action"];
              string currentController = (string)html.ViewContext.RouteData.Values["controller"];
  
              if ( String.IsNullOrEmpty( controller ) )
                  controller = currentController;
  
              if ( String.IsNullOrEmpty( action ) )
                  action = currentAction;
  
              return controller == currentController &amp;&amp; action == currentAction ?
                  cssClass : String.Empty;
          }
      }
  }
  </code></pre>
  
  <p>This works very good except for the fact that visual Studio still mark the extension method as unrecognized while developing. If I build the project everythings works, but then, after the build finish VS sign the code as not recognized. </p>
  
  <p><img src="https://i.stack.imgur.com/Jzphj.png" alt="enter image description here"></p>
  
  <p>I have added an using on top of the view as well as added the namespace in the root Views web.config file</p>
  
  <pre><code>&lt;system.web.webPages.razor&gt;
      &lt;host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
      &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.Routing" /&gt;
              &lt;add namespace="MyWebApp" /&gt;
              &lt;add namespace="MyWebApp.Resources" /&gt;
              &lt;!-- extensions namespace --&gt;
              &lt;add namespace="MyWebApp.Helpers" /&gt;
          &lt;/namespaces&gt;
      &lt;/pages&gt;
  &lt;/system.web.webPages.razor&gt;
  </code></pre>
  
  <p>Any suggestion?</p>