Home > DeveloperSection > Forums > Password field in C#
Mark Devid
Mark Devid

Total Post:102

Posted on    January-28-2014 11:51 PM


 1 Reply(s)
 3028  View(s)
Rate this:

I am using entity framework and .net 4.5 with c#5 for first time from last 2-3 days and i want to display a input type as password field but don't know how to do it

<div class="editor-field">

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

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


I want this field as hidden but i don't know how. Please help.

And also i want to check this field with

<div class="editor-label">



<div class="editor-field">

    <input id="repwd" type="password" name="repwd"/>


to confirm if the password is correct

Pravesh Singh

Total Post:412

Posted on    January-29-2014 12:48 AM

Hi Mark,

Use @Html.PasswordFor instead of @Html.EditorFor and for comparing two password your required to change model as show below

 public class ChangePasswordModel



    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]


    [Display(Name = "New password")]

    public string NewPassword { get; set; }


    [Display(Name = "Confirm new password")]

    [System.Web.Mvc.Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]

    public string ConfirmPassword { get; set; }


Don't want to miss updates? Please click the below button!

Follow MindStick