tags:

views:

52

answers:

1

whats the best way to do a redirect (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.

+4  A: 

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.

Craig Stuntz