خرید بک لینک

Vote count: 0

I've probably missed an important nugget somewhere here, however I wonder if someone could correct my understanding.

I have an MVC5 website project, all set up nicely. My applications root namespace is MyApp for examples sake.

I have some MyApp.Properties and MyApp.Models of course and onwards, all standard. Now in my Views folder my web.config is declared as so (extract) :

<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>

Which all makes sense, however in my view I want to declare my applicationSettings (Settings) which is itself in the MyApp.Properties namespace (note, I've also tested this with a basic class in MyApp.Models for sense checking). I can declare this like so :

@using MyApp.Properties
@{ Settings appSettings = new Settings(); }

Compiles fine, intellisense fine

@{ MyApp.Properies.Settings appSettings = new MyApp.Properies.Settings(); }

Compiles fine, intellisense fine

So thats nice, however I already have my root namespace included inthe web.config, so my assumption is that I can do this :

@{ Properties.Settings appSettings = new Properties.Settings(); }

This builds absolutely fine (no errors), however intellisense red underlines Properties.Settings and on page view I get a "Compilation Error" with the message :

The type or namespace name 'Properties' could not be found (are you missing a using directive or an assembly reference?)

Wierdly, if I add MyApp.Properties to the Web.config, I can declare my settings as expected with a simple @{ Settings appSettings = new Settings(); }, likewise if I add @using MyApp or @using MyApp.Properties the relevent code works fine too (as expected).

So my question is, What gives with the root namespace? Why can't I use it in my Web.config?? If this is a bone-fide rule (don't use the root namespace) where is it documented so I can teach myself a lesson???

Many thanks in advance guru's!!

asked 2 mins ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 29 بهمن 1394 ساعت: 0:15

صفحه بندی