开发者

ASP.NET MVC Area not displaying my Custom Helpers

开发者 https://www.devze.com 2023-01-27 11:59 出处:网络
I created Area called Admin. I have Custom Helper in the root folder called开发者_开发技巧 Helpers which are working fine when I use @Html.MyHelper(); but I do the samething in my Area View folder Raz

I created Area called Admin. I have Custom Helper in the root folder called开发者_开发技巧 Helpers which are working fine when I use @Html.MyHelper(); but I do the samething in my Area View folder Razor page I don't see MyHelper. I tried to add Namespaces in Area View config file but no success. Anyone tell me what I am missing?


Not sure what you mean by "Area View config file" (do you mean the web.config in your area?).

Try explicitly including the namespace in the CSHTML:

@using MvcWebApplication1.Helpers.MyCustomHelpers

Alternatively, you could register the namespace in web.config:

<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="MvcWebApplication1.Helpers.MyCustomHelpers" />
      </namespaces>
    </pages>
</system.web.webPages.razor>

NOTE: There was an issue with namespace registration with Razor in MVC3 Preview, but has been fixed in beta / RC1. See here for more info.

0

上一篇:

:下一篇

精彩评论

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