1、Model常用属性讲解
using System; using System.ComponentModel.DataAnnotations; namespace MVCStudy2.Models { public class Student { [Required(ErrorMessage = "这是必填项")] [RegularExpression(@"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$)",ErrorMessage = "请输入正确的地址"] public string Email { get; set; } [Required] public string Password { get; set; } [Required] [Compare(nameof(Password))] public string ConfirmPassword { get; set; } public DateTime? BirthDate { get; set; } [Range(1,100)] [Display(Name = "年龄")] public int Age { get; set; } } }
2、其他
1)不允许访问某一行为
将权限控制符改为private
或添加属性
[NonAction]
2)改作用的访问名称
[ActionName("xxxx")]