如何从子动作内部获取当前控制器和动作? [英] How to get current controller and action from inside Child action?
本文介绍了如何从子动作内部获取当前控制器和动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一部分视图是通过调用子操作的 RenderAction 呈现的.如何从该子操作中获取父控制器和操作.
I have a portion of my view that is rendered via RenderAction calling a child action. How can I get the Parent controller and Action from inside this Child Action.
当我使用..
@ViewContext.RouteData.Values["action"]
我取回了子操作的名称,但我需要的是父/调用操作.
I get back the name of the Child Action but what I need is the Parent/Calling action.
谢谢
顺便说一句,我将 MVC 3 与 Razor 一起使用.
BTW I am using MVC 3 with Razor.
推荐答案
如果你想从子操作本身(而不是视图)访问它,你可以使用
And if you want to access this from within the child action itself (rather than the view) you can use
ControllerContext.ParentActionViewContext.RouteData.Values["action"]
这篇关于如何从子动作内部获取当前控制器和动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文