views:

450

answers:

2

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

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

+1  A: 

MVC Futures has an AreaHelpers.GetAreaName() method. However, use caution if you're using this method. Using the current area to make runtime decisions about your application could lead to difficult-to-debug or insecure code.

Levi
+4  A: 

In MVC 2 you can use ViewContext.RouteData.DataTokens["area"]

artvolk
If not in an area, ViewContext.RouteData.DataTokens["area"] == null.