Validating a property if another property has a value on MVC 3/jQuery Validator

前端 未结 3 1391
心在旅途
心在旅途 2021-01-06 03:11

how can I use a Required Validation in a property Prop2 only if the Prop1 is true?

Ex:
public bool Prop1 { get; set; }

[Required] // I need this validation          


        
3条回答
  •  自闭症患者
    2021-01-06 03:50

    You could use MVC FoolProof Validation framework

    It has useful feature like

    [RequiredIf]
    [RequiredIfNot]
    [RequiredIfTrue]
    [RequiredIfFalse]
    [RequiredIfEmpty]
    [RequiredIfNotEmpty]
    [RequiredIfRegExMatch]
    [RequiredIfNotRegExMatch]
    
    [Is]
    [EqualTo]
    [NotEqualTo]
    [GreaterThan]
    [LessThan]
    [GreaterThanOrEqualTo]
    [LessThanOrEqualTo]
    

    Hope this would help you!

提交回复
热议问题