When performing model binding to objects, it seems that the framework will return null if there are type mismatches for any of the object's properties. For instance, consider this simple example:
public class Client
{
public string Name { get; set; }
public int Age { get; set; }
public DateTime RegistrationDate { get; set; }
}
public class ClientController : Controller
{
[HttpPatch]
public IActionResult Patch([FromBody]Client client)
{
return Ok("Success!");
}
}
If I submit a value of "asdf" for the Age property in an HTTP request, the entire client parameter will be null in the Patch method, regardless of what's been submitted for the other properties. Same thing for the RegistrationDate property. So when your FromBody argument is null in your controller action, how can you know what errors caused model binding to fail (in this case, which submitted property had the wrong type)?
[FromRoute]instead of what it should be[FromBody]. :-)