I have the following problem (I will simplify the classes to facilitate understanding):
public class Class1 {
[Required]
public int? Id_Estabelecimento { get; set; }
public string Nm_Nome { get; set; }
}
public class Class2 {
[Required]
public int Id_Classe2 { get; set; }
public int Tipo_Cadastro { get; set; }
public Classe1 CLASSE1 { get; set; }
}
The problem is as follows: If Class_Type is 1, CLASS1 (and its attributes) should not be Required, otherwise Class 2 should be validated normally.
OBS1: I can do this procedure on Controller (using ModelState Clear), but I wanted to do it on the Client Side with unobtrusive jquery.
OBS2: I know it involves conditional validation. I have already done a conditional validation involving two attributes of the same class. In this case I'm trying to "hack" the data annotations of another class.
Has anyone ever been through something like this? Or am I complicating things?