Handling Model Binding Errors when using [FromBody] in .NET Core 2.1
问题 I am trying to understand how I can intercept and handle model binding errors in .net core. I want to do this: // POST api/values [HttpPost] public void Post([FromBody] Thing value) { if (!ModelState.IsValid) { // Handle Error Here } } Where the Model for "Thing" is: public class Thing { public string Description { get; set; } public int Amount { get; set; } } However if I pass in an invalid amount like: { "description" : "Cats", "amount" : 21.25 } I get an error back like this: {"amount":[