title: How do I pass a variable from an ActionFilter to a Controller Action in C# MVC?
body: <p>Taking a simple action filter, which checks if the user is logged in and retrieves their user ID.</p>
  
  <pre><code>public class LoginFilter : ActionFilterAttribute
  {
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {    
          // Authenticate (somehow) and retrieve the ID
          int id = Authentication.SomeMethod();
          // Pass the ID through to the controller?
          .....
      }
  }
  </code></pre>
  
  <p>How could I then pass this ID through to my controller action?</p>
  
  <pre><code>[LoginFilter]
  public class Dashboard : Controller
  {
      public ActionResult Index()
      {
          // I'd like to be able to use the ID from the LoginFilter here
          int id = ....
      }
  }
  </code></pre>
  
  <p>Is there an equivalent to the ViewBag that would allow me to do this? Or some other technique that allows me to pass variables and objects between the filter and the controller action?</p>