Using CascadeMode.StopOnFirstFailure on a validator level

前端 未结 2 1412
萌比男神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:17

    According to the JeremyS' answer, I have misunderstood the purpose of the CascadeMode. It is in fact not intended to have effect on a validator level but only within a rule.

    0 讨论(0)
  • 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)
    
    0 讨论(0)
提交回复
热议问题