Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

ASP.NET Core 6 Web API : use System.Json.Text ModelBinding error message is not correct

$
0
0

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.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>