Search code examples
asp.net-mvcasp.net-mvc-3razorasp.net-mvc-3-areas

Get Area name in Views on render time at ASP.NET MVC3 Razor


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?


Solution

  • The Area name is not in the RouteData.Values but you can get it from the DataTokens collection::

    ViewContext.RouteData.DataTokens["area"]