title: How to handle model binding exceptions in ASP.NET Core MVC?
body: <p>Create a simple ASP.NET Core MVC web application from the template. Create a class called <code>Human</code>:</p>
  
  <pre><code>public class Human
  {
      public string Name { get; set; }
  
      public int Age { get; set; }
  
      public DateTime Birthday { get; set; }
  }
  </code></pre>
  
  <p>Now create a <code>HumanController</code> to post a human instance:</p>
  
  <pre><code>[HttpPost]
  public Human Post([FromBody] Human human)
  {
      return human;
  }
  </code></pre>
  
  <p>Using Fiddler or PostSharp (or any other client) post these JSON objects to this service:</p>
  
  <pre><code>{
      "Name": "someone"
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>{
      "Name": "someone",
      "Age": "invalid age"
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>{
      "Name": "someone",
      "Birthday": null
  }
  </code></pre>
  
  <p>Since <code>Birthday</code> can't be null and <code>"invalid age"</code> can't be parsed as valid model properties, what we get in our service parameter is null. That has proved to be hard to debug.</p>
  
  <p>Is there a way that we can configure ASP.NET Core MVC to either only partially bind models as much as it can, or to somehow let us hook into its default behavior so that we can catch the exception and notify client about wrong data it has sent?</p>