I\'m using the following to get the current controller and action in asp.net MVC3:
var currentAction = routeData.GetRequiredString(\"action\");
var currentCo
After your updated question and showing your code it is much more clear: you are not including a partial view. You are calling a child action. There's a huge difference between Html.Partial
and Html.Action
. So if you want to get the parent context inside this child action you could do this:
public ActionResult Menu()
{
var rd = ControllerContext.ParentActionViewContext.RouteData;
var currentAction = rd.GetRequiredString("action");
var currentController = rd.GetRequiredString("controller");
...
return View();
}
I stumbled on this page looking for a way to access the parent controllers name after a call using Partial
@Html.Partial("Paging")
This can be done in the partial view as
@{
var controller = ViewContext.RouteData.GetRequiredString("controller");
var action = ViewContext.RouteData.GetRequiredString("action");
}