简体   繁体   English

禁用客户端验证编辑器

[英]Disable Client Side Validation EditorFor

How to disable Client Side Validation from EditorFor directly ? 如何直接从EditorFor禁用客户端验证?

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, 我想在某些情况下在某些EditorFor中禁用EmailAddress验证,

@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. 您在模型上具有属性[Required] 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 参见: https : //stackoverflow.com/a/5367788/4501281

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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