문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top