I'm trying to validate fields with the ViewModel This is not working:
[Display(Name = "Insc. Estadual")]
public string InscricaoEstadual { get; set; }
[Display(Name = "Inscrição Isento")]
public bool InscricaoIsento { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (InscricaoIsento == false && string.IsNullOrEmpty(InscricaoEstadual))
{
yield return new ValidationResult("O campo Insc. Estadual é obrigatorio.");
}
}
If the InscricaoIsento
field is false
and InscricaoEstadual
is empty, it informs you that the field is required.
This function is not working, I can not understand why, it is in ViewModel.