您可以从filterContext
'sRouteData
属性中获取它:
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
RouteData rd = filterContext.RouteData;
// read from the current request RouteData the information
// you were looking for. For example to get the current controller
// and action:
string currentController = rd.GetRequiredString("controller");
string currentAction = rd.GetRequiredString("action");
}
至于呈现哪个视图,您可以从Result
属性中检索此信息:
var viewResult = filterContext.Result as ViewResultBase;
if (viewResult != null)
{
// the controller action returned a view result (either a ViewResult or PartialViewResult)
// so we could retrieve the view name here:
string viewName = viewResult.ViewName;
}
另一方面,如果控制器操作返回一个 JsonResult 你也可以提取检索它:
var jsonResult = filterContext.Result as JsonResult;
等等...