Reputation: 68830
In a Partial View _MyView.cshtml
I need to get the Controller name and the Action used to create the parent calling view.
So if /Equity/Sell was the Controller/Action used to call the view which rendered the partial view _MyView.cshtml
, then I need the value /Equity/Sell.
I don't see an object that can do that though.
Upvotes: 1
Views: 278
Reputation: 9949
In the view use:
ViewContext.RouteData.GetRequiredString("controller");
ViewContext.RouteData.GetRequiredString("action");
For posterity in a child action it is like this:
ControllerContext.ParentActionViewContext.RouteData.Values["action"];
ControllerContext.ParentActionViewContext.RouteData.Values["controller"];
Upvotes: 2