Get Current Area Name in View or Controller

前端 未结 12 1563
闹比i
闹比i 2020-11-29 00:50

How do you get the current area name in the view or controller?

Is there anything like ViewContext.RouteData.Values[\"controller\"] for areas?

12条回答
  •  执念已碎
    2020-11-29 01:23

    I know this is old, but also, when in a filter like ActionFilter, the context does not easily provide you with the area information.

    It can be found in the following code:

    var routeData = filterContext.RequestContext.RouteData;
    
    if (routeData.DataTokens["area"] != null)
        area = routeData.DataTokens["area"].ToString();
    

    So the filterContext is being passed in on the override and the correct RouteData is found under the RequestContext. There is a RoutData at the Base level, but the DataTokens DO NOT have the area in it's dictionary.

提交回复
热议问题