[training]ASP.NET MVC 5 - View data model 2

      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; }            [FileExtensions(ErrorMessage = "所上傳的檔案不是圖片")]          public string File { get; set; }            [CreditCard(ErrorMessage = "這不是信用卡格式")]          public string CreditCard { get; set; }            [DataType(DataType.Date)]          public string Date { get; set; }            [Remote("RemoteTest", "Home", ErrorMessage = "Remote屬性測試")]          public string For_Remote { get; set; }            [MetadataType(typeof(ContentMetaData))]          public partial class Content          {              private class ContentMetaData              {                  [DisplayName("編號")]                  public int Id { get; set; }                    [DisplayName("姓名")]                  [Required(ErrorMessage = "請輸入性名")]                  [StringLength(10, ErrorMessage = "姓名不得超過10字元")]                  public string Name { get; set; }                    [DisplayName("內容")]                  [Required(ErrorMessage = "請輸入內容")]                  public string Content { get; set; }              }          }      }  

Leave a Comment

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