简体   繁体   中英

Disable Client Side Validation EditorFor

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM