I use ViewContext.RouteData.Values["Controller"]
to get controller name or ViewContext.RouteData.Values["action"]
to get action name in views(actually in _Layout), but for area this ViewContext.RouteData.Values["Area"]
not worked. What is your suggestion to get area name in views programmaticaly?
Asked
Active
Viewed 2,939 times
7
-
possible duplicate of [ASP.NET MVC - Get Current Area Name in View or Controller](http://stackoverflow.com/questions/2723689/asp-net-mvc-get-current-area-name-in-view-or-controller) – nemesv Mar 13 '12 at 10:36
1 Answers
17
The Area name is not in the RouteData.Values
but you can get it from the DataTokens collection::
ViewContext.RouteData.DataTokens["area"]

nemesv
- 138,284
- 16
- 416
- 359