How to get current controller and action from inside Child action?

前端 未结 5 1403
半阙折子戏
半阙折子戏 2020-12-02 09:56

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.

W

5条回答
  •  -上瘾入骨i
    2020-12-02 10:25

    If the partial is inside another partial, this won't work unless we find the top most parent view content. You can find it with this:

    var parentActionViewContext = ViewContext.ParentActionViewContext;
    while (parentActionViewContext.ParentActionViewContext != null)
    {
        parentActionViewContext = parentActionViewContext.ParentActionViewContext;
    }
    

提交回复
热议问题