比较验证属性inASP.NET MVC3不起作用

时间:2011-08-25 12:56:28

标签: asp.net-mvc email-validation model-validation

我在ASP.NET MVC3中使用模型验证。比较电子邮件验证根本没有触发。我也为MVC3安装了DataAnnoatations Extensions。以下是我的代码。

[Display(ResourceType = typeof(Resources.Views.Account.Local.Create), Name = "EMail1")]
[Required(ErrorMessageResourceType = typeof(Resources.Views.Account.Local.Create), 
    ErrorMessageResourceName = "rqEMail1")]
[RegularExpression(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", 
    ErrorMessageResourceType = typeof(Resources.Views.Account.Local.Create), 
    ErrorMessageResourceName = "regxEMail1")]

public string EMail1 { get; set; }


[Required]
[Compare("EMail1", ErrorMessageResourceType = typeof(Resources.Views.Account.Local.Create), 
    ErrorMessageResourceName = "cmpEmail")]
[RegularExpression(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", 
    ErrorMessageResourceType = typeof(Resources.Views.Account.Local.Create), 
    ErrorMessageResourceName = "regxEMail2")]

public string EMail2 { get; set; }

1 个答案:

答案 0 :(得分:0)

如果验证在服务器端正确进行,那么请查看您在客户端包含的脚本,因为它们可能与比较验证器不兼容。特别是,检查jQuery本身的版本和jQuery.Validate插件(假设您使用的是最常用的客户端脚本)。