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();
精彩评论