4

I am using Razor for all my web pages. In my global web.config I have the following:

 <system.web>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>

In my local (to view) web.configs I have:

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <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="MyApp.WebUx.Helpers" />
        <add namespace="MyApp.Storage.Models" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

I want to make things as efficient and clean as possible so do I need to have the first of these or is just the razor section enough?

tereško
  • 58,060
  • 25
  • 98
  • 150
Samantha J T Star
  • 30,952
  • 84
  • 245
  • 427

1 Answers1

0

These namespaces are required if you are using any classes in your views from those assemblies. The are essentially global includes/using statements for each view that has the page base type of System.Web.Mvc.WebViewPage.

If you remove them, you would manually have to import the assembly namespace. See this post on how.

Community
  • 1
  • 1
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173