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

Total Post:101

Points:707
Posted on    January-28-2014 11:51 PM

 ASP.NET MVC ASP.NET MVC 
Ratings:


 1 Reply(s)
 2497  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)

</div>

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">

    Re-Password

</div>

<div class="editor-field">

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

</div>

to confirm if the password is correct



Pravesh Singh

Total Post:411

Points:2881
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

 {

    [Required]

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

    [DataType(DataType.Password)]

    [Display(Name = "New password")]

    public string NewPassword { get; set; }

    [DataType(DataType.Password)]

    [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