asp.net-mvc-3controllerfilteringglobalglobal-filter

How to pass a value from a Global Filter to the Controller?


In a MVC3 app, I need a global filter to get a value and before any controller is executed, however how can I get later that value from a Controller?

public class MyGlobalFilter : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        int i = 10;
    }
}

Solution

  • I found that it's possible to set a new ViewBag value by the action controller context as the following code

    filterContext.Controller.ViewBag.MyNewValue = 1