我如何获得的RouteData在局部视图父操作相关联? [英] How do I get the RouteData associated with the parent action in a partial view?

查看:104
本文介绍了我如何获得的RouteData在局部视图父操作相关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个PartialView的动作,我想知道与家长行动相关的RouteData。

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.

在我PartialView的行动,我检查 RouteData.Values​​ [控制器] RouteData.Values​​ [行动] ,但我只得到我PartialView控制器和动作。

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.

有什么建议?

推荐答案

- 编辑 -

它看起来像断ControllerContext(从中派生ViewContext),你可以得到ParentActionViewContext:

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

ViewContext.ParentActionViewContext.RouteData["controller"]

这篇关于我如何获得的RouteData在局部视图父操作相关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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