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

Complements the RequiredWhen attribute. Forces property to have empty value when other property has specific value.

Attribute

[RequiredEmptyWhen("OtherProperty", "value")]                         // property is required to be empty when OtherProperty == "value"
[RequiredEmptyWhen("OtherProperty", "value", NegateCondition = true)] // property is required to be empty when OtherProperty != "value"

Notes

Please note: The default error message does not mention the master condition (it says Field {0} is required to be empty, not Field {0} is required to be empty when some conditions are met). It's recommended to override the message to be more specific to your model.

Clone this wiki locally