Along with null error message, even the custom/must validation is ran and error failure is displayed.
I have set globally ValidatorOptions.CascadeMode = CascadeMode.StopOnFirstFailure;
Inside Custom can check if(motor = null) return; But is there any other way to restrict not to run custom or must validation in fluent validator.
Below is my PersonDetails model class :
Public Class PersonDetails {
public PersonName {get;set;}
}
Public Class PersonName {
public string Firstname {get;set;}
public string LastName {get;set;}
}
public class PersonApplicantValidator : AbstractValidator<PersonDetails>
{
RuleFor(x => x.PersonName ).NotNull().WithMessage("Mandatory field").Custom(
(personName, context) =>
{
if(personName.Firstname == null)
context.AddFailure("FirstName is mandatory");
});
}
Когда PersonName = null,
Актуально: Обязательное поле FirstName является обязательным
Expected : Mandatory field
Как остановить при первом сбое и не запускать кастом?