RegisterArea in ASP.NET MVC

Published on April 27, 2013 by abundantcode

Filed under ASP.NET

Last modified April 27, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 1 (1 votes)

This article have been viewed 3286 times

In the previous article, we provided you an overview of the areas in ASP.NET MVC. When a new area is created in ASP.NET MVC, a file with the area name suffixed by AreaRegistration will be created.

In the example as described in the previous article, the AbundantcodePayrollAreaRegistration.cs contains the following

using System.Web.Mvc;

namespace MvcApplication1.Areas.AbundantcodePayroll

{

public class AbundantcodePayrollAreaRegistration : AreaRegistration

{

public override string AreaName

{

get

{

return "AbundantcodePayroll";

}

}

public override void RegisterArea(AreaRegistrationContext context)

{

context.MapRoute(

"AbundantcodePayroll_default",

"AbundantcodePayroll/{controller}/{action}/{id}",

new { action = "Index", id = UrlParameter.Optional }

);

}

}

}

This class contains the RegisterArea method which is used to register the route with the pattern for the area.

In the sample above the following route is registered.

“AbundantcodePayroll/ {controller}/{action}/{id}”

Additionally, all the areas are automatically are registered via the RegisterAllAreas method which is called in the Global.asax.cs.

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

How to return Json instead of XML in ASP.NET Web API ?

When you make a call to the ASP.NET Web API action method and notice this in Google Chrome browser ,...

How to Add Web API to existing ASP.NET Web Forms Project ?

In one of the previous posts , we saw how to add the WebAPI to the existing ASP.NET MVC project. Wel...

How to Add Web API to existing ASP.NET MVC Project ?

There are times when you might want to add Web API project to one of your existing ASP.NET MVC proje...