I m using WEB API (.net 6) for my project. For validation I m using data annotation. it does not display error, the way I decorated the property
My property
public string CompanyName { get; set; }
public string CompanyCode { get; set; }
public string Address { get; set; }
public string ZipCode { get; set; }
public string MobileNo { get; set; }
All the property I validated with data annotation. below image
When my API response back, errors display like this
But I want to display all the errors in the way that I decorated my property. first it will provide error about company Name, then company code then address and go on.
Is there any way to do this.
CodePudding user response:
you have two Error Messages, remove one that is not required or replace the error message at top of the property. [Required Error Message("Error Message here...")] public string CompanyName { get; set; }
CodePudding user response:
It is working in order, so first required will be validated and as soon as it throws an error that is being returned. if you enter something in company name property then it will try to validate the regex and will share the appropriate error message specified for regex validation.
You have to use custom validation to display such kind of messages.