0

I have an entity and one attribute is required depending of some clauses. I tried to use RequiredIf but it is not working 'cause is not possible to add 2 RequiredIf in the same property.

I need to do something like this, but it is not the right way:

[RequiredIf("CountryId", 1, ErrorMessageResourceType = typeof(Resources.Contato.Contato), ErrorMessageResourceName = "MensagemNumeroConselho")]                
[RequiredIf("AreaId", 1, ErrorMessageResourceType = typeof(Resources.Contato.Contato), ErrorMessageResourceName = "MensagemNumeroConselho")]                
public string Number { get; set; }

Is there a way to do this?

tereško
  • 58,060
  • 25
  • 98
  • 150
Deise Vicentin
  • 137
  • 1
  • 4
  • 23

1 Answers1

0

It's not clear what you are trying to do: Is Number supposed to be required when one or both of the conditional attributes is present?

Either way, your best option is to add an overload to your RequiredIf constructor that takes in an array of strings, perhaps with another parameter to determine if the requiredif depends on one or all of the listed properties being present.

Then, you can just change your validation code to check each string in the array.

User
  • 1,118
  • 7
  • 23
  • this is exactly what I want: the Number must be required when one or both of the conditional attributes is presented!!! I'll try to do your suggestion. Thanks. – Deise Vicentin Aug 01 '13 at 18:25