The mistake is you are putting it in ViewBag.ProcedureSubCategoryID
while you are passing ProcedureID
int Html.DropDownList()
and also you are passing SelectList
parameter null
. A quick fix is to just replace ProcedureSubCategoryID
with ProcedureID
in Html.DropDownList()
as key in first parameter:
you have three ways to resolve this.
Way 1:
Instead of passing null
in second parameter which accepts of type SelectList
you can do something like this:
@Html.DropDownList("ProcedureID", ViewBag.ProcedureSubCategoryID as SelectList, new { @class="form-data" })
Way2:
public ActionResult Create()
{
ViewBag.DepartmentID = new SelectList(db.Departments, "ID", "Name");
ViewBag.ProcedureSubCategoryID = new SelectList(db.ProcedureSubCategories, "ID", "Name");
return View();
}
@Html.DropDownList("ProcedureSubCategoryID", null, new { @class = "form-control" })
Way 3:
or alternative is to store it in ProcedureID
in your action:
public ActionResult Create()
{
ViewBag.DepartmentID = new SelectList(db.Departments, "ID", "Name");
ViewBag.ProcedureID = new SelectList(db.ProcedureSubCategories, "ID", "Name");
return View();
}
and in View:
@Html.DropDownList("ProcedureID", null, new { @class = "form-control" })
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…