title: pass value returned from a method to action filter
body: <p>I have <code>_serviceOne</code> injected into my controller that has a method which returns an <code>int</code> value. I'm trying to pass this value into my custom action filter.</p>
  
  <p>This isn't working and I am getting the error: <code>An object reference is required for the non-static field, method, or property 'NameController._serviceOne'</code> where I try to set the <code>Number = _serviceOne.GetIntNumber</code>.</p>
  
  <p>I am aware that I can access a value if it is inside the controller (eg: controller parameter, ViewBag, ViewData, a variable in the controller), but I want to pass the value to the <code>CustomActionFilter</code> filter's <code>Number</code> property.</p>
  
  <p>The filter and service method work the way I want it to, but it won't let me pass the value from <code>_serviceOne.GetIntNumber</code> into the filter. Why is this not working, and how could I make it work?</p>
  
  <p>NameController.cs:</p>
  
  <pre><code>public class NameController : Controller
  {
      private readonly ServiceOne _serviceOne;
  
      public NameController(ServiceOne serviceOne)
      {
          _serviceOne = serviceOne;
      }
  
      [CustomActionFilter(Name = "CorrectName", Number = _serviceOne.GetIntNumber)] //does not work
      [HttpGet]
      public IActionResult Index()
      {
          return View();
      }
  }
  </code></pre>
  
  <p>CustomActionFilter.cs:</p>
  
  <pre><code>public class CustomActionFilter : ActionFilterAttribute
  {
      public string Name { get; set; }
      public int Number { get; set; }
  
      public override void OnActionExecuted(ActionExecutedContext context)
      {
          if (Name == "CorrectName" &amp;&amp; Number == 1) {
              RouteValueDictionary routeDictionary = new RouteValueDictionary { { "action", "SomeAction" }, { "controller", "NameController" } };
              context.Result = new RedirectToRouteResult(routeDictionary);
          }
  
          base.OnActionExecuted(context);
      }
  }
  </code></pre>