Asp.Net Areas

Assalamualaykum Wr Br..:)

Today we explore the Asp.Net Area Concept with a small project. Lets look few theory points:

Areas provide a way to separate a large MVC Web application into smaller functional groupings. An area is effectively an MVC structure inside an application. An application could contain several MVC structures (areas).

To accommodate large projects, ASP.NET MVC lets you partition Web applications into smaller units that are referred to as areas.

For example, a single large e-commerce application might be divided into areas that represent the storefront, product reviews, user account administration, and the purchasing system. Each area represents a separate function of the overall application.

This walkthrough demonstrates how to implement areas in an ASP.NET MVC application. The walkthrough creates the functional framework for a blog site that has the following areas:

  • Main. This is entry point to the Web application. This area includes the landing page and a log-in feature.
  • Blog. This area is used to display blog posts and to search the archive.
  • Dashboard. This area is used to create and edit blog posts.

To keep this tutorial simple, the areas do not contain logic to perform the actual tasks for the blog.

Creating the Application Structure

To begin, you will create an ASP.NET MVC project and add the folder structure for two child areas (Blog and Dashboard).

To create the application structure

  1. In Visual Studio, in the File menu, and click New Project.
  2. In the Project types window, expand the Visual Basic node or the Visual C# node, and then select the Web node.
  3. In the Templates window, select ASP.NET MVC 2 Web Application.
  4. Name the project MvcAreasApplication, set the project location, and then select the Create directory for solution check box.
  5. Click OK.
  6. In Solution Explorer, right-click the project name, click Add, and then click Area.
  7. In Area Name, type Blog and then click Add.

    An Areas folder is added to the project. The Areas folder contains a folder structure that allows each child area to have its own models, views, and controllers.

  8. In Solution Explorer, right-click the project name, click Add, and then click Area.
  9. In Area Name, enter Dashboard and then click Add.

    When you are done, the Areas folder contains two child areas, Blog and Dashboard.

    Adding Area-Specific Controllers

     You will now add area-enabled controllers and action methods for each area.

    To add area controllers

    1. In Solution Explorer, right-click the Controllers subfolder for the Blog area, click Add, and then click Controller.
    2. Name the controller BlogController and then click Add.
    3. Add the following code to the BlogController class.

Leave a Reply

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

You are commenting using your 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