Scenario: The user should fill out a form and based on his choices different properties are displayed(using jquery .show and .hide).
Problem: I want some of those properties that are shown to be required(but only when they are shown ofc). The [Required] attribute doesn’t care if the property is shown or not. So if I use [Required] the user are asked to fill out properties he can’t see.
Solution: ?
Scenario: The user should fill out a form and based on his choices different
Share
You could use the RequiredIf attribute to perform conditional validation:
Now, add a hidden field called
HiddenFooand then toggle its value when you are showing/hiding theFootextbox.Foowill be required only ifHiddenFoo="true".