Hello,
I am trying to retrieve a value from a drop down list in MVC, I am able to bind the drop down list from a table but unable to save the id of the drop down value selected back to the database.
//The following is a snippet of my Create.aspx
<%= Html.dropdownlist("departments", "Select One")%>
//The following is a snippet of my HomeController.cs
public ActionResult Create()
{
this.ViewData["departments"] = new SelectList(_service.ListDepartments(), "departmentID", "name");
return View("Create");
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(int? deptID, [Bind(Exclude = "educationID")] tblEDA empToCreate)
{
if (_service.CreateEmp(deptID, empToCreate))
return RedirectToAction("Index");
return View("Create");
}
Any help would really be appreciated. Thank you.