Conditional Required Attribute for validation
Posted
by jeriley
on Stack Overflow
See other posts from Stack Overflow
or by jeriley
Published on 2010-03-23T21:23:34Z
Indexed on
2010/03/24
12:13 UTC
Read the original article
Hit count: 221
validation
|ASP.NET
We're trying to get a conditional attribute to work, case in point, there's a boolean (checkbox) that if checked, its related text is required. So, ideally we'd have something like ...
public bool Provision { get; set; }
[ConditionalRequirement(IsNeededWhenTrue = Provision)]
public string ProvisionText { get; set; }
Is this even possible?
Alternate idea (not as elegant?)
public bool Provision2 { get; set; }
[PropertyRequired(RequiredBooleanPropertyName = "Provision2")]
public string Provision2Text { get; set; }
I'd hate to use the magic string method ... but any other ideas?
© Stack Overflow or respective owner