Reputation: 6336
I started a new Nancy project in .Net 4.5.1 using Visual Studio 2013. As view engine I'm using Razor. Everything builds and works, but I would like intellisense without using the full namespace. Is this possible?
This is my web.config:
<configuration>
<configSections>
<section name="razor" type="Nancy.ViewEngines.Razor.RazorConfigurationSection, Nancy.ViewEngines.Razor" />
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"/>
</sectionGroup>
</configSections>
<razor disableAutoIncludeModelNamespace="false">
<assemblies>
<add assembly="IC.Resources" />
</assemblies>
<namespaces>
<add namespace="IC.Web.Client.Models" />
<add namespace="IC.Resources" />
</namespaces>
</razor>
<system.web.webPages.razor>
<pages pageBaseType="Nancy.ViewEngines.Razor.NancyRazorViewBase">
<namespaces>
<add namespace="Nancy.ViewEngines.Razor"/>
<add namespace="IC.Web.Client.Models" />
<add namespace="IC.Resources" />
</namespaces>
</pages>
</system.web.webPages.razor>
</configuration>
If I use code from IC.Resources or IC.Web.Client.Models, I still need to use the full namespace.
This is at the top of my view:
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<IC.Web.Client.Models.LoginModel>
It works if I add this to the top of every page:
@using IC.Resources;
@using IC.Web.Client.Models
But I don't like to repeat this on every page. I tried adding the using to only the layout page, but that doesn't work.
@{ Layout = "_layout.cshtml"; }
Upvotes: 2
Views: 1481
Reputation: 56
If you add the System.Object definition to your pageBaseType that should negate the need to add the two using statements.
<system.web.webPages.razor>
<pages pageBaseType="Nancy.ViewEngines.Razor.NancyRazorViewBase`1[[System.Object]]">
<namespaces>
<add namespace="Nancy.ViewEngines.Razor" />
</namespaces>
</pages>
</system.web.webPages.razor>
Upvotes: 4