Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use of Areas in MVC2

what is the purpose of "Areas" in MVC2

like image 301
Xulfee Avatar asked Apr 26 '10 09:04

Xulfee


People also ask

What is use of area in MVC?

Areas allows you to separate your modules and organize Model, View, Controller, Web. config and Routing registration file into separate sections. In live MVC Project implementation we can use Areas concept for organizing project in better manageable way. Area separate logical section like Model, View, Controller, Web.

What is the benefit of using area in ASP NET MVC?

Benefits of Area in MVC Allows us to organize models, views and controllers into separate functional sections of the application, such as administration, billing, customer support and much more. Easy to integrate with other Areas created by another.

What is Microsoft ASP Net mvc2?

ASP.NET MVC 2 is a framework for developing highly testable and maintainable Web applications by leveraging the Model-View-Controller (MVC) pattern.

What is new in .NET MVC?

A new property is available to T4 files from the ASP.NET MVC T4 host that specifies the version of the . NET Framework that is used by the application. This enables T4 templates to generate code and markup that is specific to a version of the . NET Framework.


4 Answers

For a concrete example of when to use areas, consider an e-commerce site. You could have your normal controllers for the public-facing portion of the website, as well as an "admin" area to manage products, categories etc. That way you can have two completely different productController classes which have distinct Details() methods. (one for populating a public facing view with product details, and another for admin users, which might have stats on sales, etc).

like image 90
briercan Avatar answered Oct 02 '22 17:10

briercan


I'm trying them out in a CMS using the areas for break downs of the content by type. So I have areas for Calendar, News/Blog, Navigation and Pages (a catch-all fall through).

In my brief experience so far, the benefit of areas are:

  • Makes it obvious when calling something from a separate part of the application (ie in a RenderAction).
  • Makes it easier to see the connection between Models, Views and Controllers for that part of the application as they are no longer all mixed together.
  • Registration of routes for the area are right there -- no longer all mixed together.

I do think that acknowledging the first point is important. For some, the extra work to do RenderAction and similar calls to other areas may be a deal breaker. I've also noticed the routing with areas may be subtly different: I relied on a registered handler in web.config but the routing no longer worked for it after moving my catch-all route to an area. I had to add an explicit ignore for the image handler.

like image 27
Cymen Avatar answered Oct 02 '22 17:10

Cymen


This is the top hit when googling for "Areas MVC2":

Areas provide a means of grouping controllers and views to allow building subsections of a large application in relative isolation to other sections. Each area can be implemented as a separate ASP.NET MVC project which can then be referenced by the main application. This helps manage the complexity when building a large application and facilitates multiple teams working together on a single application together.

like image 44
Mitch Wheat Avatar answered Oct 02 '22 15:10

Mitch Wheat


it create sub project in your application

like image 20
yahoomarketiers Avatar answered Oct 02 '22 15:10

yahoomarketiers