Example: We have a conditional field. This conditional field is a radio button with the following two values ββof yes and no. Let's say the name of this drum is "AAA".
This conditional field "AAA" should only be displayed if the other field of the "BBB" switch is set to yes. (The values ββfor the βBBBβ switch are also βyesβ and βno.β)
But the conditional field "AAA" should be displayed with the value set to "NO", means "yes", or "no" should be set when the field is first displayed.
The problem arises from the requirement that the conditional field βAAAβ should ONLY be required when the (non-conditional) field βBBBβ is set to βyesβ - and is not required when the field βBBBβ is set to βnoβ.
(Sounds like I didn't hear anything about the statement if, or? But hold on and keep reading ...)
Believe me, it will not be a problem for me to solve this topic when we use "ModelState", but we are talking here about Validation (Data Annotations), which looks like this:
public class Input1FormModel { [Required(ErrorMessageResourceName="Error_Field_AAA_Empty", ErrorMessageResourceType=typeof(Resources.MyDialog))] public int AAA { get; set; } }
I fully understand ALSO these lines of code - I believe; -)
...
//property limits public int UpperBound { get { return DateTime.Now.Year; } } public int LowerBound { get { return 1900; } }
...
[NotNullValidator] [PropertyComparisonValidator("LowerBound", ComparisonOperator.GreaterThan)] [PropertyComparisonValidator("UpperBound", ComparisonOperator.LessThanEqual)] public int? XYZ { get; set; }
But how to solve the dependence described above (AAA β BBB)?
Change "return DateTime.Now.Year;" to a function call that first checks another field and returns true or false? But how to get there the value of another field?