-2
我暫一個下拉列表如下:modelstate.isvalid總是假
@Html.DropDownListFor(model => model.Department.Id, new SelectList(db.PhoenixIKDepartments.ToList(), "Id", "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,名稱和代碼正確填寫下拉列表嗎?
預先感謝您!