I've MVC5 application and in the create view i have user and password fields.

I put values in the user and password field and when I enter to edit mode i see just the user value in the text box

and the password field is empty,why?

when I debug the code I see that in the end of the edit ( return View(UserPass); ) i got the object with the values and than it call to the view(razor) and I dont see the value in the pass text box ...

Any idea why the user is exist and password not? I just want it to be field with asterisks in the edit mode...

In the edit and the create view I use:

<div class="form-group">
    @Html.LabelFor(model => model.Password, new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.PasswordFor(model => model.Password)
        @Html.ValidationMessageFor(model => model.Password)
    </div>
</div>
有帮助吗?

解决方案

Passwords are not prepopulated to prevent accidential submits and not to have un encrypted passwords.

check below link.

ASP.Net MVC3 Html.PasswordFor does not populate

其他提示

Use this:

@Html.PasswordFor(model => model.Password,new{@Value=Model.Password})

Notice that Value:v should be uppercase

Rendering the value of a password into the html source is a huge security risk. Its preventing you from leaking your passwords. Otherwise someone could view the page source and see:

<input type="password" value="password123" />

I would recommend doing the following:

@Html.PasswordFor(model => model.Password, new { placeholder = "********" })

This will put some 'visual' asterisks in the textbox which will disappear when the user starts entering an actual value. Its not supported by all browsers, but its something.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top