开发者

asp.net mvc3, how to add namespacing globally?

开发者_StackOverflow社区

I wrote a htmlhelper, then added the namespace in the web.config file.

   <pages>
        <namespaces>
            <add namespace="System.Web.Helpers" />
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Routing" />
            <add namespace="System.Web.WebPages"/>
            <add namespace="MvcApplication3.HtmlHelpers"/>
        </namespaces>
    </pages>

for some reason this is not working, in the page, I still need to import this namespace to use the htmlhelper.

@using MvcApplication3.HtmlHelpers

what did I do wrong ?


Be sure to add this to the web.config in the 'Views' folder, not to the root web.config. Then it should work. Example:

  <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="itWORKS" />
        <add namespace="itWORKS.MVC" />
        <add namespace="OfertaPlus.Services" />
      </namespaces>
    </pages>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜