For using Attribute Routing in areas, registering areas and [RouteArea(...)]
definitions are required.
In RouteConfig.cs
:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
AreaRegistration.RegisterAllAreas();
}
}
In a sample area controller attribute routing definition :
[RouteArea("AreaName", AreaPrefix = "AreaName")]
[RoutePrefix("SampleAreaController")]
public class SampleAreaController : Controller
{
[Route("Index")]
public ActionResult Index()
{
return View();
}
}
For using Url.Action
links in Areas :
@Url.Action("Index", "SampleAreaController", new { area = "AreaName" })