开发者

ChildAction wants to know who is caller?

In child action method, i need to know which action method invoked before me so i can detect which action method ca开发者_运维百科use to invoke me.

How can i know it ?


Inside a child action simply use the ParentActionViewContext:

[ChildActionOnly]
public ActionResult Foo()
{
    var parentActionName = ControllerContext
        .ParentActionViewContext
        .RouteData
        .GetRequiredString("action");
    ...
}


@Darin, I think this is more simplified,

 RouteData.Route.GetRouteData(HttpContext).Values["action"]


fastest is

StackFrame sframe = new StackFrame(1);

if you want full stack trace view use

StackTrace frame = new StackTrace();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜