Wouter
Wouter

Reputation: 1353

Get name of area in controller

Is their a way to get the name of the Area in a controller (programmatically)?

Following doesn't seem to work:

String currentArea = ControllerContext.RouteData.DataTokens["area"].ToString();

Upvotes: 3

Views: 1679

Answers (1)

tmg
tmg

Reputation: 20393

We can get it from RouteData:

var areaName = string.Empty;
object area = null;
if (RouteData.Values.TryGetValue("area", out area))
{
    areaName = area.ToString();
}

Upvotes: 6

Related Questions