码迷,mamicode.com
首页 > Windows程序 > 详细

c# MVC模式学习笔记_数据验证

时间:2017-04-21 14:15:30      阅读:303      评论:0      收藏:0      [点我收藏+]

标签:com   size   required   require   str   ann   验证   weight   ssd   

改变显示字段名称 设计字段规范 

1.引用

1 using System.ComponentModel;
2 using System.ComponentModel.DataAnnotations;

2.DisplayName值

 public class Book
    {
        public int BookID { get; set; }   
        [DisplayName("ISBN")]
        public string isbn { get; set; }
        [DisplayName("图书名称:")]
        [Required(ErrorMessage="图书名称必填")]
        public string bookName { get; set; }
        [DisplayName("作者")]
        [Required(ErrorMessage = "作者必填")]
        public string author { get; set; }
          [DisplayName("出版社")]
          [Required(ErrorMessage = "出版社必填")]
        public string press { get; set; }
          [DisplayName("出版日期")]
          [Required(ErrorMessage = "出版日期必填")]
        public DateTime pressDate { get; set; }
          [DisplayName("定价:")]
        public decimal price { get; set; }
          [DisplayName("尺寸:")]
        public string size { get; set; }
         [DisplayName("重量:")]
        public double? weight { get; set; }
         [DisplayName("开本:")]
        public int? format { get; set; }
    }

3.设置字段范围

[StringLength(50)]
 [StringLength(10,MinimumLength=2)]

range 指定数值型范围 

 [Range(0,10000)]

 

c# MVC模式学习笔记_数据验证

标签:com   size   required   require   str   ann   验证   weight   ssd   

原文地址:http://www.cnblogs.com/zzzting/p/6743338.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!