Home/MVC/How to create Areas in MVC 4 with Razor

How to create Areas in MVC 4 with Razor

 How to use MVC Areas feature using Razor

 What is Areas ?

  •  In MVC we have default folders (view, model, controller…) structure, If application grew larger, then it will be complicated to maintain a modules and structure logic for the file in the solution.
  •  To overcome this, MVC provide areas,Using MVC area has its own folder structure which allow us to keep separate controllers, views, and models…
READ  How to handle Multiple submit buttons in the same form/page

Creating Areas

Step 1:

To add an area to application, right-click on the project —> select Add —> Area option as shown below.

area 1

Step 2:

Enter the Module/Areas Name in the “Add name Prombt” as shown below

area 2

Click ADD button to create  structure(Areas) as shown below

area 3

Same way we can create more areas based on our modules…

READ  Output Caching Attribute in ASP.NET MVC

Step 3:

Create Controller by right clicking the controllers folder then create view , as shown in below

area 5

area 6

Step 4:

Here we start discuss about “How to call Module_1(Areas) from main project”.

Here i am creating actionlink for calling the view inside the Module_1

@Html.ActionLink(“Go to Module-1 Index”,”Index”,”Module_1″,new {area =”Module_1″},null)

  • “Go to Module-1 Index” :   Name of link
  • Index : Name of the Action
  • Module_1 : Name of the controller
  • new {area =”Module_1″} : Name of the area

Step 5 :  Run the Application


area 7

By clicking the link, it will redirect to Module_1 (inside the Areas) as shown below

READ  Creating reusable method using @helper in MVC Razor

area 8

Leave A Comment