简体   繁体   English

在MVC4中使用HTML.EditorForPassword()

[英]Work with HTML.EditorForPassword() in MVC4

I created a "Editlogin.cshtml" page where I can edit all properties of an user. 我创建了一个“ Editlogin.cshtml”页面,可以在其中编辑用户的所有属性。 My user has password so when I change a his password then it works okay. 我的用户有密码,所以当我更改密码时,它可以正常工作。 However when I do not write any passwors, my page has to write me a password, but sometimes I do want to leave the previous password. 但是,当我不写密码时,我的页面必须给我写一个密码,但是有时我确实想保留以前的密码。 I use Entity Framework and I use an attribute for Password property in a model class: 我使用实体框架,并在模型类中为密码属性使用属性:

    [Required(ErrorMessage = "Please type Password", AllowEmptyStrings = false)]
    public global::System.String Password
    {
        get { //omitted}
        set { //omitted}
    }

It is a double-edged weapon. 这是一把双刃武器。 When I create new user, I must have to write new password. 创建新用户时,必须输入新密码。 However, if I edit an user, I would like sometimes to leave a previous password. 但是,如果我编辑用户,有时我想保留以前的密码。 How to solve it? 怎么解决呢?

为什么不通过单独的功能(更改密码)从表单编辑中选择退出密码更改,出于安全目的,重置密码字段非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM