2
Late!
I am performing a complex validation on a specific class with the following code (reduced to simplify):
public class Classe1 : IValidatableObject
{
[Key]
public int Id_Classe1 { get; set; }
[Required]
public int Id_Estado { get; set; }
public virtual Classe2 CLASSE2 { get; set; }
public Classe1() {
CLASSE2 = new Classe2();
}
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
if (this.Id_Estado == 1)
{
if (CLASSE2.Nm_Classe2 == null)
yield return new ValidationResult("Campo Nome é obrigatório.", new string[] { "CLASSE2.Nm_Classe2" });
}
}
In the controller (Modelstate.Isvalid) the validation is ok. Now I need to reflect this validation in Client-Side, with jquery unobtrusive. Can someone give me some guidance on how to do?
Already took a look at the plugin Validator ?
– Franchesco
Yes. I use it. I happen to want the following: Case
Id_Estado
(attribute ofclasse1
) be 1, then force the typing ofNm_Classe2
(attribute ofclasse2
that is not[Required]
). Exactly what you are doing in the code above. It would be like putting a[Required]
conditional on attributeCLASSE2
, but since this attribute is an object of another class it simply does not validate in client-side.– Felipe