11+ Year IT Industry Experience, Working as Technical Lead with Capgemini | Consultant | Leadership and Corporate Trainer | Motivational and Technical Speaker | Career Coach | Author | MVP | Founder Of RVS Group | Trained more than 4000+ IT professionals | Azure | DevOps | ASP.NET | C# | MVC | WEB API | ANGULAR | TYPESCRIPT | MEAN | SQL | SSRS | WEB SERVICE | WCF... https://bikeshsrivastava.blogspot.in/ http://bikeshsrivastava.com/

How to use Area in MVC ?

Today i am going to explain about "area" in MVC.In very short, we can say "an area is sub part of MVC application, can be defined as Smaller functional units in an ASP.NET MVC project with its own set of whole features(model,view,controller,web.config).Inside a single MVC application we can create multiple "area".we can understand area after showing this image given below.


Area image

Blog,Help Desk,Shopping is Area which is inside a Main application MVC project.

How To use area inside MVC application:-

Step 1:-Create a MVC Project.

MVC page

Step 2:-You can see your application without area.Run application without area it'll working fine.
Solution page

Step 3:-Add area in your application.see image.

add area

Now you can add multiple area in any type of MVC application.Now i am adding a area name is "Mens".see image

Show solution

Now i am going to add next area name is "Womans".see image.

show area

Now you can see in image I've added two area in Main application.
Now you are able to create model,view,controller inside any area according your requirment as well as Main application.
Note:-If you are using any area in Mvc Application then you'll have to change your Route.config file because default routing have ambiguity problem .otherwise after run application throw error like this.see image.

Step 4:-Create controller , action for each area and view.

Error page

But you can hit directly using area path .see image.
Output

Step 5:-Change route.config file.see  image.

routing

If you want default route is any area then you'll have to add 
.DataTokens["area"]= "Test"; line inside route.config file.otherwise  by default page working fine from Main application. Be aware about route configuration (Controller name,Action name);

Now you are ready to work with area in MVC.

Step 6:- How to redirect one area to other area in mvc?
Hyperlink from one area view to other area view use this code.

 @Html.ActionLink("Redirect to other View", "Index", "Home", new { Area = "womans" },null)


Step 7:- Run application.








You have just read an article that categorized by title Interview Question / MVC by title How to use Area in MVC ?. You can bookmark this page with a URL https://bikeshsrivastava.blogspot.com/2016/07/part-30how-to-use-area-in-mvc.html. Thank You!
Author: Bikesh Srivastava - Monday, July 18, 2016

2 comments to "How to use Area in MVC ?"

Life Is Complicated, But Now programmer Can Keep It Simple.