7

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?

tereško
  • 58,060
  • 25
  • 98
  • 150
Saeid
  • 13,224
  • 32
  • 107
  • 173
  • 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 Answers1

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