Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Field password returned empty to view in edit mode

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>
like image 544
Jean Tehhe Avatar asked Oct 20 '25 10:10

Jean Tehhe


2 Answers

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

like image 174
malkam Avatar answered Oct 22 '25 00:10

malkam


Use this:

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

Notice that Value:v should be uppercase

like image 42
shahrooz.bazrafshan Avatar answered Oct 22 '25 00:10

shahrooz.bazrafshan