我正在填写一个下拉列表,如下所示:
@Html.DropDownListFor(model => model.Department.Id, new SelectList(db.PhoenixIKDepartments.ToList(), "Id", "Name"))
我希望有 Id、Code 和 Name,但只有 Id 和 ModelState 是假的。
public class Phoenix_IK_Persons
{
[Key]
public int Id { get; set; }
[StringLength(50)]
public string Name { get; set; }
[StringLength(500)]
public string Surname { get; set; }
[StringLength(50)]
public string Registry { get; set; }
public Phoenix_IK_Departments Department { get; set; }
}
public class Phoenix_IK_Departments
{
[Key]
public int Id { get; set; }
[StringLength(50)]
[Required(AllowEmptyStrings=false, ErrorMessage="Lütfen Kod Giriniz!")]
public string Code { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "Lütfen Ad Giriniz!")]
[StringLength(500)]
public string Name { get; set; }
}
您能帮我用 ID、名称和代码正确填写下拉列表吗?
先感谢您!