Using CascadeMode.StopOnFirstFailure on a validator level

前端 未结 2 1444
萌比男神i
萌比男神i 2021-02-19 19:00

From the FluentValidation documentation I learned that I can abort validation by setting the cascade mode.

RuleFor(x => x.Surname)
.Cascade(CascadeMode.StopOn         


        
2条回答
  •  失恋的感觉
    2021-02-19 19:32

    You can set CascadeMode at the global level by setting

    ValidatorOptions.CascadeMode = CascadeMode.StopOnFirstFailure;
    

    or at property level by

    RuleFor(x => x.PropertyName)
        .Cascade(CascadeMode.StopOnFirstFailure)
    

提交回复
热议问题