ASP.NET MVC Namespaces in Web.config instead of Views - ASP.NET MVC Best Practices

I don't really like to see namespaces in my Views in ASP.NET MVC for several reasons, but one of the more important reasons is that if you change the namespace of the classes you use in your views you then have to go to every view and update the namespaces appropriately. Nothing more painful than forgetting to update those namespaces and/or having to change them on the views.

There is a handy-dandy area in the Web.config where you can add namespaces for your views once that will be referenced in all your views. Add them there and if you ever need to change namespaces you only have to make the change once in the Web.config.

Before with the ugly namespace in the ASP.NET MVC View:

 

ASP.NET MVC Namespace in View

 

After with the namespace in the Web.config and removed from the ASP.NET MVC View:

 

ASP.NET MVC Namespace in Web.config

 

It truly does help with the maintainability of your web applications, ASP.NET Webforms or ASP.NET MVC :)

 

David Hayden

 

Related Topics:

 

posted on Tuesday, October 13, 2009 3:05 PM

Main

David Hayden Google +

David Hayden Twitter

Health & Fitness

JavaScript Patterns Book Review

HTML 5 and CSS3 - Develop with Tomorrow's Standards Today

Professional ASP.NET Design Patterns Book Review

Beginning Mac Programming Book Review

C# in Depth Book Review

ASP.NET MVC

Orchard CMS

Categories