title: ASP.NET Core customize the error when model binding fails
body: <p>I try to apply back end validation whenever empty or invalid values are send to ASP.NET Core Web API endpoint, but I can't figure out how to handle model binding failure errors. </p>
  
  <p>Getting this error probably from <code>ModelState</code> when submitting invalid values: <code>totalPrice: ["Could not convert string to decimal: . Path 'totalPrice', line 1, position 71."]
  0: "Could not convert string to decimal:     . Path 'totalPrice', line 1, position 71."</code> It looks like model binding is failing and error is displayed directly to the client. </p>
  
  <p>I have pretty simple controller decorated with <code>ApiController</code> attribute. </p>
  
  <pre><code>[ApiController]
  public class ProductsController
  {
      [HttpPost]
      public IActionResult Post([FromBody]CreateProductDto model)
      {    
          model.Id = await service.CreateProduct(model);
  
          return CreatedAtRoute(
              routeName: "GetProduct", 
              routeValues: new { id = model.Id }, 
              value: model
          );
      }
  }
  </code></pre>
  
  <p>and my DTO model</p>
  
  <pre><code>public class CreateProductDto
  {
      [Required(ErrorMessage = "Invalid value")]
      public decimal totalPrice { get; set;}
  
      public int count { get; set; }
  }
  </code></pre>
  
  <p>Is there a way to customize the text from model binding errors? I would like to prevent sensitive info to be send and provide friendly feedback to the client?</p>