Alex Rivera | Logout

ASP.Net MVC3 Html.PasswordFor does not populate

Asked 2011-04-12T23:37:09.753
56

In my view I have the following element

  @Html.PasswordFor(model => model.Password)

This is on a screen that creates/updates user details. When I am trying to update the user this field remains blank. When I change this element to a TextBoxFor it gets the data. How do I get to populate the Password field.

Edit
Report

2 Answers

162

As described above, it is better to avoid doing this for security reason. if you still want to persist the password so that you proceed from where the current validation failed, you can use the HTML helper with html attribute parameter:

     Html.PasswordFor(x => x.Password, new { value = Model.Password})
answered 2011-07-07T02:54:38.427
7

MVC protects you from doing something like this for a reason. You shouldn't actually be able to do this because the users password should not be stored unencrypted and unhashed. If your goal is to end end up on http://plaintextoffenders.com/ though, you can do something like:

<input type="password" name="Password" id="Password" value="@Model.Password" />
answered 2011-04-13T00:01:17.347

Your Answer