I’m manually validating and adding the errors to my model as follows:
var validationResult = model.Validate(new ValidationContext(model, null, null));
foreach (var error in validationResult)
{
foreach (var memberName in error.MemberNames)
{
ModelState.AddModelError(memberName, error.ErrorMessage);
}
}
if (!ModelState.IsValid)
{
}
If the model is not valid I want to return a JSON array containing the error messages. That’s tripping me up a little.
or if you want only an array of the error messages: