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?
Ended up rolling my own. Basically you create a valiation method that does your normal check of yes, no, whatever and collects them in some kind of error collection. The rub with this is sending it BACK to the Model itself. So I got lazy and strongly typed it as such …
so then you’re validation statements have something like this in them …
Then within the controller, a simple check and port it BACK to the model if it (isn’t valid of course) …
There’s probably a more cleaner way of doing this but so far, this has been working just fine.