spooti
spooti

Reputation: 247

When extending HtmlHelper can't get intellisense to work without a using statment

I have extended HtmlHelper, then when trying to use it in partial view it doesn't show in intellisense, I have added the namespace to the web.config. the only way to get it to work was to add a using statement to the partial view. Am I missing something? I would prefer not to add using statements to every view using it.

Upvotes: 0

Views: 460

Answers (1)

codingbadger
codingbadger

Reputation: 44032

Ensure that you are editing the config file in your Views directory.

<system.web.webPages.razor>
  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
    <namespaces>
      <add namespace="System.Web.Mvc" />
      <add namespace="System.Web.Mvc.Ajax" />
      <add namespace="System.Web.Mvc.Html" />
      <add namespace="System.Web.Routing" />
      <add namespace="Your.Namespace.Goes.Here" />
    </namespaces>
  </pages>
</system.web.webPages.razor>

Also, sometimes you might need to close and reopen the .cshtml file or even restart Visual Studio.

Upvotes: 1

Related Questions