-
Notifications
You must be signed in to change notification settings - Fork 4
RequiredWhen
Michal Altair Valášek edited this page May 28, 2024
·
4 revisions
Makes property required when some other property has specific value.
[RequiredWhen("OtherProperty", "value")] // property is required when OtherProperty == "value"
[RequiredWhen("OtherProperty", "value", NegateCondition = true)] // property is required when OtherProperty != "value"The default error message does not mention the master condition (it says Field {0} is required, not Field {0} is required when some conditions are met). It's recommended to override the message to be more specific to your model.