-2
I’m trying to validate fields with Viewmodel This way it’s 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 field InscricaoIsento
for false
and InscricaoEstadual
is empty, it informs that the field is mandatory.
This function is not working, I can not understand why, is in ViewModel.
If you use the notation of [Required] it may suit you.
– Diogo Antas
If the Entered field is false and the Entered field is empty, it informs that the field is mandatory. But if the Registration field is true, the Registration Status does not need to be filled Unfortunately it does not meet. and
– Mariana
This has not been answered here https://answall.com/questions/331767/condi%C3%A7%C3%A3o-if-com-required-viewmodel/331806#331806 ? Otherwise, put more information on this question, such as the full Model code and Controller Action so we can help.
– Renan
@Renan it is not working.
– Mariana
Put more information on this question, such as the full Model code and Controller Action so we can help.
– Renan
I just need the validation of the field, but as if as described, this way is not validating.
– Mariana