I know this question is asked several times for other frameworks and languages but I wanted to know how can I really stop my model validation once it gets the first error in ASP.NET Core 2.1?
[Required(ErrorMessage = Email.requiredErrorMessage)]
[DataType(DataType.EmailAddress, ErrorMessage = Email.formatErrorMessage)]
[StringLength(Email.maximumLength, MinimumLength = Email.minimumLength, ErrorMessage = Email.rangeErrorMessage)]
[EmailExists(ErrorMessage = Email.doesNotExistsMessage)]
public string email { get; set; }
[Required(ErrorMessage = ConfirmationCode.requiredErrorMessage)]
[RegularExpression(ConfirmationCode.regularExpression, ErrorMessage = ConfirmationCode.formatErrorMessage)]
public string confirmationCode { get; set; }
Above code is API model validation and upon making a Patch request, I receive following response:
"email":[
"This email does not exist in database"
],
"confirmationCode":[
"Confirmation code format is invalid"
]
}
I do not want model validation to continue when it has ensured that email doesn't exist in database, just return that error and do not continue the validation anymore.