Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the RouteData associated with the parent action in a partial view?

In the action for a PartialView, I'd like to know the RouteData associated with the Parent Action.

This partial view is part of my masterpage template, and I'd like for it to know the Controller and Action that was called as part of the page rendering.

In my PartialView's action, I inspect RouteData.Values["controller"] and RouteData.Values["action"], but I only get the controller and action for my PartialView.

Any suggestions?

like image 961
JMP Avatar asked Aug 03 '10 18:08

JMP


1 Answers

--edit--

It looks like off of the ControllerContext (from which ViewContext derives) you can get the ParentActionViewContext:

ViewContext.ParentActionViewContext.RouteData["controller"]
like image 96
Eilon Avatar answered Oct 22 '22 19:10

Eilon