Skip to content
Michal Altair Valášek edited this page May 28, 2024 · 4 revisions

Makes property required when some other property has specific value.

Attribute

[RequiredWhen("OtherProperty", "value")]                         // property is required when OtherProperty == "value"
[RequiredWhen("OtherProperty", "value", NegateCondition = true)] // property is required when OtherProperty != "value"

Notes

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.

Clone this wiki locally