[training]ASP.NET MVC 5 – 檢視資料模型 1

    public class Index
    {
        [DisplayName("必選修")]

        public string required { get; set; }

        /*name只能有一個,所以這兩段先註解掉
        [Required(ErrorMessage = "學生姓名不得為空白")]
        public string name { get; set; }

        [StringLength(10, ErrorMessage = "學生姓名不得超過10字元")]
        public string name { get; set; }
        */

        [StringLength(10, ErrorMessage = "學生姓名必須介於2-10字元", MinimumLength = 2)]
        public string name { get; set; }

        [Range(0, 100, ErrorMessage = "得分必須介於0~100之間")]
        public int point { get; set; }

        [System.Web.Mvc.Compare("re_password", ErrorMessage = "兩次密碼輸入不一致")]
        //上面沒有using System.Web.Mvc,所以這邊就要打完整的命名空間
        public string password { get; set; }
        public string re_password { get; set; }

        [RegularExpression( @"^[0-9]{2,4}-?[0-9]{3,4}-?[0-9]{-4}$", ErrorMessage = "請輸入正確的電話號碼")]
        public string phone { get; set; }

        [EmailAddress(ErrorMessage = "這不是E-mail格式")]
        public string studentmail { get; set; }

        [Url(ErrorMessage = "這不是網址標準格式")]
        public string url { get; set; }
    }

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.