我在 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; }