Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Modular Structure in ASP.NET MVC Application

0.00/5 (No votes)
21 Oct 2012 1  
Areas gives the opportunity to separate a large ASP.NET MVC Web application into smaller functional groups or loosely coupled modules.

Introduction

Functionally independent modules can be accumulated in ‘Areas’ for ASP.NET MVC application. This approach is helpful for each module to develop separately and independently. An area is effectively an MVC structure inside an application. An application could contain several MVC structures (areas).

Steps to Create ‘Areas’

  1. Create MVC 4 empty application.
  2. Right-click on the project and select Add -> Area… option. 
  3. Write a name for ‘Areas’. Example: Module1.

    In this way, it is possible to add/create several Areas. Notice that the area registration class file (Module1AreaRegistration.cs) will be created under the Module1 folder. This .cs class inherits the AreaRegistration base class.

  4. At the RouteConfig.cs class in ‘App_Start’ folder, add the following start-up Controller Builder.;
ControllerBuilder.Current.DefaultNamespaces.Add("Main.Controllers"); 

Solution Structure

If anyone gets the following error message, "Compiler Error Message: CS0234: The type or namespace name Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)" 

Install the latest System.Web.Optimization package. To install the package, use Package Manager Console (Tools -> Library Package Manager -> Package Manager Console) and execute the command below: 

Install-Package -IncludePrerelease Microsoft.AspNet.Web.Optimization

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here