Vis*_*ara 17 asp.net-mvc asp.net-mvc-4
是否可以将确认密码文本框的文本与@Html.PasswordFor(model=>model.Password)?进行比较
?
@using (Html.BeginForm())
{
<table>
<tr>
<td>@Html.LabelFor(model => model.Password)</td>
<td>@Html.PasswordFor(model => model.Password)</td>
<td>@Html.ValidationMessageFor(model => model.Password)</td>
</tr>
@*Here I want to take "Confirm Password" and want to compare it with "Password" in View(.cshtml only) as
I have not taken ConfirmPassword in my model.*@
<tr>
<td>
<input type="submit" value="Create" />
</td>
</tr>
</table>
}
Run Code Online (Sandbox Code Playgroud)
请建议任何方式或解决方案,
如何compare password并confirm password没有得到示范确认密码属性.谢谢....
Sen*_*der 21
使用Compare DataAnnotation它将很容易比较密码但是如果来自数据库的模型genrate使用NotMapped,使用代码优先策略的实体框架中的NotMapped属性
[Required]
public string Password { get; set; }
[NotMapped] // Does not effect with your database
[Compare("Password")]
public string ConfirmPassword { get; set; }
Run Code Online (Sandbox Code Playgroud)
COL*_*OLD 12
更改您的模型以包含确认密码变量
[Required]
public string Password { get; set; }
[Compare("Password")]
public string ConfirmPassword { get; set; }
Run Code Online (Sandbox Code Playgroud)
只需[NotMapped]在数据模型中添加上面的确认密码属性即可
[NotMapped]
[Required(ErrorMessage = "Confirm Password required")]
[CompareAttribute("NewPassword", ErrorMessage = "Password doesn't match.")]
public string ConfirmPassowrd { get; set; }
Run Code Online (Sandbox Code Playgroud)
通过这种方式,它不会检查ConfirmPassword数据库表中的属性
| 归档时间: |
|
| 查看次数: |
34661 次 |
| 最近记录: |