如何从内儿童动作电流控制器和行动? [英] How to get current controller and action from inside Child action?

查看:81
本文介绍了如何从内儿童动作电流控制器和行动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的观点,即通过调用的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.

感谢

BTW我使用MVC 3剃须刀。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆