【问题标题】:compare validation attribute inASP.NET MVC3 not working比较 ASP.NET MVC3 中的验证属性不起作用
【发布时间】:2011-11-03 16:18:15
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多