2011-08-25 53 views
0

我在ASP.NET MVC3中使用了模型验证。比较电子邮件验证完全没有触发。我也为MVC3安装了DataAnnoatations扩展。以下是我的代码。比较ASP.NET MVC3中的验证属性不起作用

[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; } 

回答

0

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