本文介绍了是比较验证器Bugged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是非常基本的,但它总是返回false的比较验证。

This is very basic but it always returns false on the compare validation. Anyone else running in to this problem?

 public class UsersRegisterUserViewModel
{
    [DisplayName("E-Mail Address")]
    [Required(ErrorMessage = "E-Mail Address is required")]
    [RegularExpression(@"^[A-Za-z0-9_\-\.]+@(([A-Za-z0-9\-])+\.)+([A-Za-z\-])+$", ErrorMessage = "Invalid E-mail Address")]
    public string RegUsername { get; set; }

    [Required]
    [Display(Name = "Password")]
    [DataType(DataType.Password)]
    public string Password { get; set; }

    [Required]
    [Display(Name = "Confirm Password")]
    [Compare("Password", ErrorMessage = "Passwords must match")]
    [DataType(DataType.Password)]
    public string RegConfirmPassword { get; set; }
}


推荐答案

MVC3比较属性当独立于帐户控制器比较密码时。似乎它是硬编码只能使用帐户控制器。

1.剪切并通过电子邮件,密码,确认密码从RegisterModel到一个新的文件名为ViewModels / ShortRegister.cs
2.剪刀代码(电子邮件,密码,确认密码)从寄存器视图,并过去它局部视图,调用它_shortRegistration。
3.创建一个名为ShortRegistration的新控制器。将部分视图添加到ShortRegistation。
5.添加相关的jquery脚本

MVC3 Compare attribute is buggy when comparing passwords independently of Account Controller. It seems it is hardcoded to only work with Account controller.
1. Cut and past email, password, confirm password from RegisterModel into a new file called ViewModels/ShortRegister.cs2. Cut razor code ( email, password, confirm password) from register view and past it into partial view, call it "_shortRegistration".3. Create a new controller called "ShortRegistration". Add the partial view into ShortRegistation.5. Add related jquery scripts


  1. 在主页上创建一个链接到ShortRegistration。 / li>
  2. 确认错误消息总是触发错误消息。

  3. 从部分视图确认中移除电子邮件,比较功能可用。

  4. 将userName添加到部分视图和视图模型,比较功能失败,密码确认错误消息总是显示错误消息。

这个bug已经修复了吗?我禁用了比较属性和写jquery和CCS修复这个!我很乐意通过电子邮件发送代码,以证明比较是错误的。

Has this bug been fixed? I disabled Compare attribute and wrote jquery and CCS to fix this! I am more than happy to email the code to prove that Compare is buggy.

这篇关于是比较验证器Bugged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 02:19