C#中的密码字段

时间:2013-12-25 06:57:36

标签: c# .net entity-framework

我在过去的2-3天内首次使用实体框架和.net 4.5和c#5,我想将输入类型显示为密码字段但不知道如何操作

<div class="editor-field">
    @Html.EditorFor(model => model.Password)
    @Html.ValidationMessageFor(model => model.Password)
</div>

我希望这个字段是隐藏的,但我不知道如何。请帮忙。

我还想用

检查这个字段
<div class="editor-label">
    Re-Password
</div>
<div class="editor-field">
    <input id="repwd" type="password" name="repwd"/>
</div>

确认密码是否正确

1 个答案:

答案 0 :(得分:1)

使用@Html.PasswordFor代替@Html.EditorFor并比较您需要更改模型的两个密码,如下所示

 public class ChangePasswordModel
 {

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "New password")]
    public string NewPassword { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirm new password")]
    [System.Web.Mvc.Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }
}