Introduction: Asp.net MVC allows us to split
an application into multiple logical groups/modules which are called areas. In
this demo, I’ll create two areas – Finance and Marketing. Each area will hold
and display employee list of its own department.
Steps:
Create a MVC 5 project.
Add Area: In the solution
explorer, right click the project | Add| Area | enter name (Finance in this
example). Add another area and name it (Marketing in this example).
After adding the areas, the
structure should look like as shown in screenshot below.
Check configuration: Two
important files - FinanceAreaRegistration.cs and MarketingAreaRegistration.cs
files are being added. These files are used to configure the routing system for
the area.
The configuration of the
area is called from application_start method in global.aspx.
Implement Finance Module:
Add Finance class and
financeRepository class under the “Models” folder for “Finance” area.
The classes are being
implemented with the following code:
Add controller
(FinanceController) under controller
folder. Write the following code in FinanceController.cs file.
Add view: Right click on Index
action method of financeController and create a view called “index” by
accepting default option. The structure of “Finance” area should look like this.
Write the following code in
“index.cshtml” file under “view” folder. This view will implement “finance”
model.
Debug the project. The
output shows “Finance” and “Marketing” tabs. Click on “Finance” tabs and here
is the output.
Also, the "Marketing" area has been implemented.Here is the output: