title: asp net core web api custom model validation
body: <p>Asp net core web API, I am trying to return a custom response for the model validator. But ValidateModelFilter is not called when the required field, not in the request.</p>
  <p>ValidateModelFilter.cs</p>
  <pre><code>public class ValidateModelFilter : ActionFilterAttribute
  {
      public override void OnActionExecuting(ActionExecutingContext context)
      {
          if (!context.ModelState.IsValid)
          {
               var response = new Model
               {
                   error = context.ModelState.ToString()
               };
               context.Result = new BadRequestObjectResult(response);
           }
      }
  }
  </code></pre>
  <p>Startup.cs</p>
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddMvc(options =&gt; options.Filters.Add(typeof(ValidateModelFilter)));
  }
  </code></pre>
  <p>I am getting a response like this</p>
  <pre><code>{
    &quot;errors&quot;: {
      &quot;Firstname&quot;: [
        &quot;The Firstname field is required.&quot;
      ]
    },
    &quot;type&quot;: &quot;https://tools.ietf.org/html/rfc7231#section-6.5.1&quot;,
    &quot;title&quot;: &quot;One or more validation errors occurred.&quot;,
    &quot;status&quot;: 400,
    &quot;traceId&quot;: &quot;|e6752549-4142e91f1074e978.&quot;
  }
  </code></pre>
  <p>I want to return a response like</p>
  <pre><code>{
  &quot;error&quot;: &quot;The Firstname field is required.&quot;
  }
  </code></pre>