MVC Attribute, Validate Field based on the values of at least 2 other fileds

75 views Asked by At

Good day,

I am using MVC4 and Foolproof validation.

I am trying to validate a field based on the values of at least 2 other fields.

public int pos1 { get; set; }
public int pos2 { get; set; }

[RequiredIf("pos1",1,ErrorMessage="some error message" )]
public int? IrdKsOption { get; set; }

RequireIf can on be specified once. RequireIf only takes 1 fieldname and value.

How would i go about doing something like this

public int pos1 { get; set; }
public int pos2 { get; set; }

[RequiredIf("pos1,pos2",[1,5],ErrorMessage="some error message" )]
public int? IrdKsOption { get; set; }

so that if pos1=1 and pos2=5 validation should fail

0

There are 0 answers