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

screenshot-1

screenshot-2

screenshot-3

screenshot-5

Step 2: Right click on the project and Add Area

Screenshot (6).png

Screenshot (7).png

Screenshot (9).png

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

screenshot-10screenshot-11

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

screenshot-12screenshot-13screenshot-14

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}

Screenshot (15).png

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s