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
[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 will get the error message 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.
New contributor
Lan Lin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.