-
Notifications
You must be signed in to change notification settings - Fork 11
Property cascade mode
Vsevolod Pilipenko edited this page Jul 19, 2022
·
1 revision
You can set for your properties two behaviors of failures:
-
CascadeMode.Continue
- all validation rules will be checked and show all messages of it. -
CascadeMode.Stop
- if validation rule has messages, all following are ignored.
Default behavior is CascadeMode.Continue
.
There are three way to specify property cascade mode. They are ordered by priority.
builder.RuleFor(vm => vm.Email)
.WithPropertyCascadeMode(CascadeMode.Stop)
.NotEmpty().When(vm => vm.PhoneNumber, phoneNumber => string.IsNullOrEmpty(phoneNumber))
.Must(IsValidEmail);
builder.PropertyCascadeMode = CascadeMode.Stop;
or just like this if your use separate class for rules:
PropertyCascadeMode = CascadeMode.Stop;
ValidationOptions
.Setup()
.UsePropertyCascadeMode(CascadeMode.Stop);