title: ASP.NET Core Action Filter Doesn't Get Called
body: <p>I have an ASP.NET Core API (.Net Core 2.1) and I implemented an Action Filter using this article </p>
  
  <p><a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-2.1#action-filters" rel="noreferrer">https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-2.1#action-filters</a></p>
  
  <p>In my Model, I use Data Annotations to validate the model, and I added the ValidateModel attribute for the Action in my Controller.</p>
  
  <pre><code>    [HttpPost("CreateShipment")]
      [ValidateModel]
      public IActionResult CreateShipment([FromBody] CreateShipmentRequest request)
      {
           if (ModelState.IsValid)
           {
              //Do something
           }
           return Ok();
      }
  </code></pre>
  
  <p>I used Postman to test this, and my Action Filter gets called only if the Model is valid. If my request is missing a required field or some value is out of range, Action Filter doesn't get called. Instead I receive a 400 bad request with the model state in the response.</p>
  
  <p>I implemented the Action Filter because I want to customize my model validation error. My understanding is that Action Filters get called at the time of model binding. Can someone help me figure out why this is happening and how to get the Action Filter to work?</p>
  
  <p>UPDATE: I found the solution 2 seconds after posting the question, and the link @Silvermind posted below is great info too.</p>
  
  <p>I added the following line to my Startup.cs </p>
  
  <pre><code>services.Configure&lt;ApiBehaviorOptions&gt;(options =&gt;
  {
       options.SuppressModelStateInvalidFilter = true;
  });
  </code></pre>
  
  <p>It's well documented here on the Microsoft site.
  <a href="https://docs.microsoft.com/en-us/aspnet/core/web-api/index?view=aspnetcore-2.1#automatic-http-400-responses" rel="noreferrer">https://docs.microsoft.com/en-us/aspnet/core/web-api/index?view=aspnetcore-2.1#automatic-http-400-responses</a></p>