Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Current Area Name in View or Controller

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

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

like image 752
user202448 Avatar asked Apr 27 '10 17:04

user202448


People also ask

How do you access the variable of the controller in the view?

OK, the simple answer is, you need to know the . Net type being returned from your query when you set the scrap variable in your controller. Whatever that type is, that's what type your @model needs to be. Either that, or use the ViewBag --but again, without IntelliSense support since it's a dynamic .

How do I return specific view on a controller?

To return a view from the controller action method, we can use View() method by passing respective parameters. return View(“ViewName”) – returns the view name specified in the current view folder (view extension name “. cshtml” is not required. return View("~/Views/Account/Register.


1 Answers

From MVC2 onwards you can use ViewContext.RouteData.DataTokens["area"]

like image 100
artvolk Avatar answered Sep 25 '22 21:09

artvolk