title: Asp.net Web API - return data from actionfilter
body: <p>I want to return a json object from the wep api actionfilter.
  How can I achieve this?</p>
  
  <p>I can return the object from action but I need to return some data from the actionfilter on some condition.</p>
  
  <p>Thanks in advance.</p>
  
  <hr>
  
  <p>Edit: 1
  When I changed the code like the following, the browser still loading without any response and ends in timeout error.</p>
  
  <pre><code>  public class ValidationActionFilter : ActionFilterAttribute
  {
  
      public override void OnActionExecuting(HttpActionContext actionContext)
      {
  
  
          var modelState = actionContext.ModelState;
          if (!modelState.IsValid)
          {
              List&lt;string&gt; arr = new List&lt;string&gt;();
              foreach (var key in modelState.Keys)
              {
                  var state = modelState[key];
                  if (state.Errors.Any())
                  {
                      string er = state.Errors.First().ErrorMessage;
                      if (!string.IsNullOrEmpty(er))
                      {
                          arr.Add(er);
                      }
                  }
              }               
  
             var output =  new Result() { Status = Status.Error.ToString(), Data = null, Message = arr };
              actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.BadRequest, output, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
          }     
  
  
      }
  }
  </code></pre>