password attributes c# code example

Example 1: password attributes c#

@using HtmlHelperDemo.Models@model UserModel 

Html.PasswordFor Example

@using (Html.BeginForm("Index", "Home", FormMethod.Post)){ //Basic password Field Example @Html.Password("BasicPassword")
//Strongly Typed Hidden Field @Html.PasswordFor(m => m.Password) @Html.ValidationMessageFor(m=>m.Password, "", new { @class = "error"})
@Html.PasswordFor(m => m.ConfirmPassword) @Html.ValidationMessageFor(m => m.ConfirmPassword, "", new { @class = "error" })

}

Value: @ViewBag.BasicPassword


Value: @ViewBag.StrongPassword


Example 2: password attributes c#

using System.ComponentModel.DataAnnotations; namespace HtmlHelperDemo.Models{    public class UserModel    {        public int UserId { get; set; }        public string UserName { get; set; }         [Required(ErrorMessage ="Password is Required.")]        public string Password { get; set; }         [Required(ErrorMessage = "Confirmation Password is Required")]        [Compare("Password", ErrorMessage = "Password Must Match")]        public string ConfirmPassword { get; set; }    }}

Example 3: password attributes c#

@model User

@Html.PasswordFor(m => m.Password)

Tags:

Misc Example