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

我与影子孤独终老i 提交于 2019-12-04 19:51:40

问题


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?


回答1:


--edit--

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

ViewContext.ParentActionViewContext.RouteData["controller"]


来源:https://stackoverflow.com/questions/3399701/how-do-i-get-the-routedata-associated-with-the-parent-action-in-a-partial-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!