比较密码并在ASP.Net MVC中确认密码 [英] Compare password and confirm password in ASP.Net MVC
本文介绍了比较密码并在ASP.Net MVC中确认密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将确认密码文本框的文本与
@Html.PasswordFor(model=>model.Password)
?
Is it possible to compare confirm password textbox's text with
@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>
}
请提出任何方法或解决方案,
Please suggest any way or solution,
如何在未获得Model中的确认密码属性的情况下compare password
和confirm password
.谢谢....
How to compare password
and confirm password
without getting confirm password property in Model. Thanks....
推荐答案
使用Compare
DataAnnotation
可以很容易地比较密码,但是如果模型是从数据库生成的,则使用NotMapped
,
Using Compare
DataAnnotation
it will be easy to compare password but if model genrate from database use NotMapped
, NotMapped Properties In An Entity Framework Using A Code-First Strategy
[Required]
public string Password { get; set; }
[NotMapped] // Does not effect with your database
[Compare("Password")]
public string ConfirmPassword { get; set; }
这篇关于比较密码并在ASP.Net MVC中确认密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文