I post the data by [FromBody]
, can not get the correct error message
I have a model
like this
public class ReservationReplyViewModel{ [Required] public DateOnly DueDate { get; set; } [Required] public DateOnly CommitDate { get; set; } public string? Comment { get; set; }}
And this is my action method:
[HttpPost("{reservation_no}/Reply")]public async Task<IActionResult> ReplyAsync(string reservation_no, [FromBody] ReservationReplyViewModel model){ // do something}
Then I post the data with
{"DueDate": null,"CommitDate": null,"Comment": null}
I get an error like
The model field is required
but I want to get the error message like
"DueDate is required." and "CommitDate is required."
I don't know how to handle with errors after Json deserialization.
Please help.