sec*_*oat 4 c# passwords model view asp.net-mvc-3
我正在尝试使用MVC 3创建一个用户注册页面,这样我就可以更好地理解它是如何工作的过程,幕后发生的事情等等.当我试图[Compare]用来检查看到的时候,我遇到了一些问题.用户输入两次相同的密码.
我首先尝试将该ComparePassword字段添加到我的用户模型中,并发现由于我在数据库中没有该字段而无法按照我想要的方式工作,因此显而易见的答案是使用包括ComparePassword字段在内的相同信息创建视图模型.
所以我现在已经创建了一个User模型和一个RegistrationViewModel,但是看起来[Compare]密码上没有返回任何内容,例如无论我放在两个框中,当我点击创建它时都没有错误,这在我看来意味着它已成功验证.
我不确定我正在做什么或不做什么来使这项工作正常.我已经尝试更新jQuery.Validate到最新版本,因为在旧版本中报告了一些错误,这对我的努力没有帮助.
以下是我正在使用的所有代码.
public class RegistrationViewModel
{
[Required]
[StringLength(15, MinimumLength = 3)]
[Display(Name = "User Name")]
[RegularExpression(@"(\S)+", ErrorMessage = " White Space is not allowed in User Names")]
[ScaffoldColumn(false)]
public String Username { get; set; }
[Required]
[StringLength(15, MinimumLength = 3)]
[Display(Name = "First Name")]
public String firstName { get; set; }
[Required]
[StringLength(15, MinimumLength = 3)]
[Display(Name = "Last Name")]
public String lastName { get; set; }
[Required]
[Display(Name = "Email")]
public String email { get; set; }
[Required]
[Display(Name = "Password")]
[DataType(DataType.Password)]
public String password { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Re-enter Password")]
[Compare("Password", ErrorMessage = "Passwords do not match.")]
public String comparePassword { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3379 次 |
| 最近记录: |