2
我使用Visual Studio 2013在.NET 4.5.1中开始了一个新的Nancy项目。 作为视图引擎,我使用的是Razor。 一切都建立和工作,但我想不使用完整的命名空间,而是想智能感知。 这可能吗?南希的剃刀智能感知
这是我的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>
如果我使用IC.Resources或IC.Web.Client.Models代码,我仍然需要使用完整的命名空间。
这是我的观点的顶部:
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<IC.Web.Client.Models.LoginModel>
它的工作原理,如果我加入这个在每个页面的顶部:
@using IC.Resources;
@using IC.Web.Client.Models
但我不喜欢在重复这每一页。 我试着将使用添加到布局页面,但这不起作用。
@{ Layout = "_layout.cshtml"; }
真的很有帮助!但是你能解释一下''[[System.Object]]'语句吗? – Avlin
这是来自.net某处的类型定义。我在使用p.GetType()之前就已经看到过这一点。最初的定义是“Nancy.ViewEngines.Razor.NancyRazorViewBase”。不要问我为什么这样。 –
CyberFox