iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 22
0
自我挑戰組

ASP.NET MVC5從入門到退坑系列 第 22

[Day22]電子商城(二)

  • 分享至 

  • xImage
  •  

建立會員登入欄位

public class MemberLoginView
    {
        [Display(Name ="會員帳號")]
        [Required(ErrorMessage ="請輸入會員帳號")]
        public string UserName { get; set; }
        [Display(Name = "會員密碼")]
        [Required(ErrorMessage = "請輸入會員密碼")]
        public string Password { get; set; }
    }

建立Member資料表驗證欄位

[MetadataType(typeof(MemberMetadata))]
    public partial class Member
    {
        private class MemberMetadata
        {
            [Display(Name ="帳號")]
            [Required(ErrorMessage ="請輸入帳號")]
            [StringLength(30,MinimumLength=6,ErrorMessage ="帳號長度需6~30字元")]
            public string Account { get; set; }
            public string Password { get; set; }
            [Display(Name ="姓名")]
            [StringLength(20,ErrorMessage ="姓名長度最多為20字元")]
            [Required(ErrorMessage ="請輸入姓名")]
            public string Name { get; set; }
            [Display(Name ="Email")]
            [Required(ErrorMessage ="請輸入Email")]
            [EmailAddress(ErrorMessage ="這不是Email格式")]
            public string Email { get; set; }
            public string AuthCode { get; set; }
            public string IsAdmin { get; set; }
        }
    }

建立會員註冊欄位驗證

public class MemberRegisterView
    {
        public Member newMember { get; set; }
        
        [Display(Name ="密碼")]
        [Required(ErrorMessage ="請輸入密碼")]
        public string Password { get; set; }

        [Display(Name ="確認密碼")]
        [Compare("Password",ErrorMessage ="密碼輸入不一致")]
        [Required(ErrorMessage ="請輸入確認密碼")]
        public string PasswordCheck { get; set; }

    }

建立會員修改密碼的欄位驗證

public class MemberChangePasswordView
    {
        [Display(Name ="舊密碼")]
        [Required(ErrorMessage ="請輸入密碼")]
        public string Password { get; set; }
        [Display(Name ="新密碼")]
        [Required(ErrorMessage ="請輸入密碼")]
        public string NewPassword { get; set; }
        [Display(Name ="新密碼確認")]
        [Required(ErrorMessage ="請輸入密碼")]
        [Compare("NewPassword",ErrorMessage ="兩次密碼不一致")]
        public string NewPasswordCheck { get; set; }

        
    }

上一篇
[Day21]電子商城(一)
下一篇
[Day23]電子商城(三)
系列文
ASP.NET MVC5從入門到退坑30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言