Html.Password in MVC

The Html.Password helper renders a password field. It’s much like the TextBox helper, except that it does not retain the posted value, and it uses a password mask. The following code:

@Html.Password("UserPassword")

results in:

<input id="UserPassword" name="UserPassword" type="password" value="" />

The strongly typed syntax for Html.Password, as you’d expect, is Html.PasswordFor. Here’s how you’d use it to display the UserPassword property:

@Html.PasswordFor(m => m.UserPassword)
Tagged . Bookmark the permalink.

Leave a Reply