views:

51

answers:

1

I have a form for creating a new account and it has a password field in it. I'm using view models to pass data to the controller action and back to the form view. When the user enters their details in, and clicks submit, if validation fails and it returns them to the same view passing back in the view model, it won't default the password to what they entered.

How can I get it to do this? Or should I even try?

+1  A: 

You can set the password after validation by explicitly calling:

<%= Html.Password("Pwd", Model.Pwd) %>

As for motivation I've seen both behaviours in the web, but probably I would choose to leave the password empty and make the user retype the password, hence leaving the Password Helper behaviour as it is.

bruno conde
And I *almost* get why it is left empty, but not really... it's just causing frustration for the user... is it really any more secure?
Max Schmeling
This is the code I used <%: Html.PasswordFor(m => m.Password, new { value = Model.Password })%>
Max Schmeling