这是我所有的模型课
public class Student
{
[Required(ErrorMessage = "First Name Required")] // textboxes will show
[Display(Name = "First Name :")]
[StringLength(5, ErrorMessage = "First Name cannot be longer than 5 characters.")]
public string FirstName { get; set; }
[Required(ErrorMessage = "Last Name Required")] // textboxes will show
[Display(Name = "Last Name :")]
[StringLength(5, ErrorMessage = "Last Name cannot be longer than 5 characters.")]
public string LastName { get; set; }
[Required(ErrorMessage = "DOB require")] // datepicker will show
[Display(Name = "DOB :")]
[DataType(DataType.Date)]
public DateTime Dob { get; set; }
[Required(ErrorMessage = "State Required")] // drodown will show
[Display(Name = "State :")]
public List<State> State { get; set; }
[Required(ErrorMessage = "City Required")] // drodown will show
[Display(Name = "City :")]
public List<City> City { get; set; }
[Required(ErrorMessage = "Language known Required")] // group of checkboxes will show
[Display(Name = "Language known :")]
public List<Language> Language { get; set; }
[Required(ErrorMessage = "Sex Required")] // group of radio button will show
[Display(Name = "Sex :")]
public List<Sex> Sex { get; set; }
[Required(ErrorMessage = "Computer Course Required")] // listbox will show
[Display(Name = "Computer Course Done :")]
public List<ComputerCourse> ComputerCourse { get; set; }
}
我可以这样填充吗?
var model = new Student()
{
FirstName = "John",
LastName = "Doe",
Dob = DateTime.Now,
State = new list<State>()
{
new state({ID="1" , Name = "test1"});
new state({ID="2" , Name = "test2"});
new state({ID="3" , Name = "test3"});
};
}
特别看到这段代码....它是否有效,因为我现在不在我的电脑之前。
State = new list<State>()
{
new state({ID="1" , Name = "test1"});
new state({ID="2" , Name = "test2"});
new state({ID="3" , Name = "test3"});
};
请告诉我是否有任何区域需要编辑或更改模型人口的代码。谢谢