Reputation: 1353
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
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