1为了防止数据库表结构修改后,实体产生变化,把在原有类文件上设置的校验都给清空了,做如下修改
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace MyMVCEfDemo.Models
{
[MetadataType(typeof(StudentValidate))]
public partial class Student
{
}
public class StudentValidate
{
//public Int32 Id { get; set; }
[Required(ErrorMessage="姓名为必录项")]
[RegularExpression(@"^[\w\s]{2,6}$",ErrorMessage="姓名长度范围为2-6之间")]
public string Name { get; set; }
[RegularExpression(@"^[\w\s]{5,10}$", ErrorMessage = "姓名长度范围为5-10之间")]
public string Address { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace MyMVCEfDemo.Models
{
[MetadataType(typeof(StudentValidate))]
public partial class Student
{
}
public class StudentValidate
{
//public Int32 Id { get; set; }
[Required(ErrorMessage="姓名为必录项")]
[RegularExpression(@"^[\w\s]{2,6}$",ErrorMessage="姓名长度范围为2-6之间")]
public string Name { get; set; }
[RegularExpression(@"^[\w\s]{5,10}$", ErrorMessage = "姓名长度范围为5-10之间")]
public string Address { get; set; }
}
}