0

How to disable Client Side Validation from EditorFor directly ?

I have this code in my Model

[Display(Name = "Correo", ResourceType = typeof(UsuarioRNECRESX))]
[Required(ErrorMessage = null, ErrorMessageResourceName = "CorreoRequerido", ErrorMessageResourceType = typeof(UsuarioRNECRESX))]
[EmailAddress(ErrorMessage = null, ErrorMessageResourceName = "CorreoFormato", ErrorMessageResourceType = typeof(UsuarioRNECRESX))]
public string Correo { get; set; }

I would like in some cases disable the EmailAddress validation in some EditorFor like this,

@Html.EditorFor(m => m.Correo, new { cols = "100", rows = "5", ngModelParent = "usuario"})

How could I do this from view ?

I've tried this

Html.EnableClientValidation(false);
Html.EnableClientValidation(true);

but that code disable all validations.

1 Answers1

0

You have the Attribute [Required] on the Model. One approach would be to create a separate model for each instance where you want it to be validated or not. See: https://stackoverflow.com/a/5367788/4501281

Ryan C
  • 572
  • 5
  • 18