Password field in C#

Total Post:102


 3783  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

  1. Re: Password field in C#

    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; }

      Modified On Apr-04-2018 02:12:52 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.