I have an issue with using declarative helpers in the App_Code directory. I created a base webviewpage for my views, which has my localization method in it. I also have a collection of enums to use for my helpers, which revolve around CSS names.
For instance, DataRole is an enum referring to the allowed CSS classes for display and GetStr is a method of my base class to print the localization value of the label:
@helper ReadOnlyColumns(DataRole role, string label, string contents)
{
<div class="@role">@GetStr(label)</div>
}
My web.config has the definition for the base page type, and the correct namespaces to include. These settings work for views not in the App_Code directory.
Does anyone have any ideas how to make the App_Code directory work? Should I put a web.config inside it? I am at a loss.
I know you can do @implements and @using, and that works. But I am trying to build the foundation for our software and don't feel it should be necessary to include things that will be used on absolutely every page we write.
Edit, this is my web.config settings in the root, and every views directory:
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPag开发者_开发技巧es.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="Company.Web.BaseWebViewPage">
<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="Company.Web" />
<add namespace="Company.Web.Enums" />
</namespaces>
</pages>
</system.web.webPages.razor>
Thanks,
Brad
Pages in App_Code
are hard-coded in WebRazorHostFactory
to inherit the HelperPage
class.
You cannot change that default.
精彩评论