我嘗試採取從數據庫性別實體(男或女),我想表明它在下拉框中:在asp.net mvc的選擇數據庫多個實體
控制器:
List<Gender> list2 = db.Gender.ToList();
ViewBag.GenderList = new SelectList(list2, "GenderID", "GenderType");
查看:
@Html.DropDownListFor(model => model.GenderID, ViewBag.GenderList as SelectList,"--select--",new { @class="form-control"})
我的錯在哪裏?我需要幫助
性別類
public class GenderViewModel
{
public int GenderID { get; set; }
public string GenderN { get; set; }
}
個人類
public class PersonalViewModel
{
public int PersonalID { get; set; }
public string PName { get; set; }
public string PLastname { get; set; }
public System.DateTime DOB { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string PPassword { get; set; }
public int GenderID { get; set; }
public int PAuthorisation { get; set; }
public bool PStatus { get; set; }
public int ShopId { get; set; }
public System.DateTime JobStartDate { get; set; }
public string GenderType { get; set; }
public string ShopName { get; set; }
}
您是否看到異常?什麼HTML呈現? –
你可以顯示性別? – Xique
我把它放在上面... – muco