whats the best way to do a red开发者_如何学编程irect (preferably a redirect to action) from within an ActionFilterAttribute?
I want to be able to pass data into the controller action from within the ActionFilterAttribute as well.
To redirect, override OnActionExecuting
and assign a new RedirectToRouteResult
to filterContext.Result
:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary { { "action", "newActionName" },
{ "actionArgument", someData } });
}
To assign data when redirecting, put it into the route, as shown above.
精彩评论