我可能在这里错过了一些重要的信息,但是我想知道是否有人可以纠正我的理解,或者至少确认我没有丢失我的豆子。
我有一个MVC5网站项目,所有设置都很好。我的应用程序根命名空间是MyApp
,例如。
我当然有一些MyApp.Properties
和MyApp.Models
,所有标准。现在在我的Views文件夹中,web.config
被声明为(提取):
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="MyApp" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<!-- ... other standard config ... -->
<configuration>
这一切都有意义,但在我看来,我想声明我的applicationSettings(Settings
),它本身就在MyApp.Properties
命名空间中(注意,我也用基本测试了这个)用于感知检查的MyApp.Models
中的类)。我可以这样声明:
@using MyApp.Properties
@{ Settings appSettings = new Settings(); }
编译精细,智能感知
@{ MyApp.Properies.Settings appSettings = new MyApp.Properies.Settings(); }
编译精细,智能感知
这很好,但是我已经在web.config中包含了我的root命名空间,所以我的假设是我可以这样做:
@{ Properties.Settings appSettings = new Properties.Settings(); }
这构建绝对正常(没有错误),但是智能感知红色强调Properties.Settings
并且在页面视图中我得到了一个&#34;编译错误&#34;信息:
类型或命名空间名称&#39;属性&#39;找不到(你错过了使用指令或汇编引用吗?)
很奇怪,如果我将MyApp.Properties
添加到Web.config,我可以使用简单的@{ Settings appSettings = new Settings(); }
按预期声明我的设置,同样如果我添加@using MyApp
或@using MyApp.Properties
相关代码也可以正常工作(如预期的那样)。
所以我的问题是,根命名空间的含义是什么?为什么我不能在我的Web.config中使用它?如果这是一个愚蠢的规则(不要使用根命名空间),那么它会记录在哪里,所以我可以自学一课???
非常感谢提前大师!!