I've created an ASP.NET Core SPA application using React as my frontend. I'm trying to display all validation errors, but it seems that only the first error is returned and I don't know why.
Here is my DTO class that contains validation attributes:
public class ProductCreateDto
{
[Display(Name = "Name")]
[MinLength(10)]
public string Name { get; set; }
[Display(Name = "Description")]
[MinLength(10)]
public string Description { get; set; }
[Display(Name = "Price")]
public double Price { get; set; }
}
This is the data that is sent to server:
{
"name": "aav",
"description": "aa",
"price": ""
}
This is the response from server:
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "00-cc641ad6d94b3947abf9425292a70071-a22e2a3181071947-00",
"errors": {
"$.price": [
"The JSON value could not be converted to System.Double. Path: $.price | LineNumber: 3 | BytePositionInLine: 15."
]
}
}
As you can see, the errors object does not contains name and description validation error messages.
errorsis an object, it's property$.priceis an array