RegisterArea in ASP.NET MVC
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
C#
x
43
43
1
using System.Web.Mvc;
2
3
namespace MvcApplication1.Areas.AbundantcodePayroll
4
5
{
6
7
public class AbundantcodePayrollAreaRegistration : AreaRegistration
8
9
{
10
11
public override string AreaName
12
13
{
14
15
get
16
17
{
18
19
return "AbundantcodePayroll";
20
21
}
22
23
}
24
25
public override void RegisterArea(AreaRegistrationContext context)
26
27
{
28
29
context.MapRoute(
30
31
"AbundantcodePayroll_default",
32
33
"AbundantcodePayroll/{controller}/{action}/{id}",
34
35
new { action = "Index", id = UrlParameter.Optional }
36
37
);
38
39
}
40
41
}
42
43
}
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.
Leave Your Comment