How do you implement @using in all views in Asp.Net MVC 3?

All I want to do is enable this:

@using MyProject.WebUI.Properties 

In all my views without having to enter them in each view, is there a way to do this in ViewStart or Web.Config? Thanks.

+8
namespaces asp.net-mvc asp.net-mvc-3 razor
source share
1 answer

Add a namespace to the web.config views below the namespace element:

 <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="MyProject.WebUI.Properties" /> </namespaces> </pages> </system.web.webPages.razor> 

Note that you may need to close and reopen the view file that you want intellisense to have these changes affect.

+29
source share

All Articles