Create Areas in the MVC project

Introduction to Area

Areas are logical grouping of Controller, Models and Views and other related folders for a module in MVC project.

Steps to create

Step 1: Create a new MVC project in the visual studio

Step 2: Right click on the project and Add Area

MVC automatically adds a full structured folder in the Area1 with the code of “AreaRegistration” for MVC to auto register Area when project is Run.

Step 3 : Add new controller in the new area

Step 4: Add new View to the Index action method in controller

Step 5: Run the application and to access the view in the area follow the following syntax

http://localhost:{port number}/{Area Name}/{Controller Name}/{Page Name}

This helps in many ways:

  1. Separate the Large code into small modules
  2. Keep code maintainable
  3. Divide a Big Project into multiple small Logical Areas (Each as One Module)
  4. Add remove modules on demand

I have been working with Areas to design many different Architecture Design that helps in modular design plug and play module even during the runtime and deployed Instance on IIS.

Try yourself and happy to share.