开发者

How to RedirectToAction from within an ActionFilterAttribute?

开发者 https://www.devze.com 2022-12-14 14:43 出处:网络
whats the best way to do a red开发者_如何学编程irect (preferably a redirect to action) from within an ActionFilterAttribute?

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.

0

精彩评论

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