@code { private Dummy DummyModel = new Dummy(); private class Dummy { [Required(ErrorMessage = "姓名不可以为空")] [DisplayName("姓名")] public string? Name { get; set; } [Required(ErrorMessage = "年龄不可以为空")] [DisplayName("年龄")] public int Age { get; set; } [DisplayName("生日")] public DateTime BirthDay { get; set; } = DateTime.Today.AddYears(-20); [Required(ErrorMessage = "请选择一种爱好")] [DisplayName("爱好")] public IEnumerable Hobby { get; set; } = new List(); [Required(ErrorMessage = "请选择学历")] [DisplayName("学历")] public EnumEducation? Education { get; set; } } private IEnumerable? Educations { get; set; } private enum EnumEducation { [Description("小学")] Primary, [Description("中学")] Middel } private IEnumerable Hobbys = new List() { new SelectedItem("游泳", "游泳"), new SelectedItem("登山", "登山"), new SelectedItem("打球", "打球"), new SelectedItem("下棋", "下棋") }; ///
/// OnInitialized 方法 ///
protected override void OnInitialized() { base.OnInitialized(); // 初始化参数 var list = new List() { new SelectedItem("", "请选择 ...") }; list.AddRange(typeof(EnumEducation).ToSelectList()); Educations = list; } }