ASP.NET MVC CompareAttribute与客户端验证

时间:2013-12-29 12:23:56

标签: c# asp.net-mvc mvvm

我正在CompareAttribute使用ViewModel,如此:

[Required]
[StringLength(100, ErrorMessage = "{0} should be atleast {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }

[Required]
[StringLength(100, ErrorMessage = "{0} should be atleast {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Comfirm password")]
[System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = "The passwords provided should be the same")]
public string ConfirmPassword { get; set; }

jquery.validate.unobtrusive.js一起,这将触发我的ComfirmPassword属性与Password属性不同。但我的价值观是一样的!

我一直在谷歌上搜索,并且有很多关于这个主题的主题 - 但提供的“修复”似乎都不适用于我的代码。

生成的标记如下所示:

密码

<input type="password" name="Password" id="Password" data-val-required="The field Password should be filled." data-val-length-min="6" data-val-length-max="100" data-val-length="Password should be atleast 6 charecters long." data-val="true" class="form-control">

ConfirmPassword

<input type="password" name="ConfirmPassword" id="ConfirmPassword" data-val-required="The field Confirm password should be filled" data-val-length-min="6" data-val-length-max="100" data-val-length="Password should be atleast 6 charecters long." data-val-equalto-other="*.Password" data-val-equalto="'Confirm password' and 'Password' does not match." data-val="true" class="form-control">

我注意到在ConfirmPassword属性标记中,其中一个数据属性是:data-val-equalto-other="*.Password"。这有点不对吗?

0 个答案:

没有答案