HI everyone,
I am working in MVC4 Razor I have created a form where i bind the dropdown with Database dropdown successsfully bind the data but when I submit the data then
It shows me error - Value cannot be null.Parameter name: items
Model:
public class DepartmentModel
{
public string deptId { get; set; }
public string deptName { get; set; }
}
View :
@using (Html.BeginForm("alumniSurvey", "important_link", FormMethod.Post))
{
<div class="form-group">
@{
@Html.DropDownList("department", new SelectList(ViewBag.deptList, "deptId", "deptName"), "-- Select Department --", new { @class = "form-control" })
@Html.Hidden("hid_department")
@Html.Hidden("hid_course")
}
</div>
}
the form is too long so button is not showing here there is input button in my design page I add ony dropdowlist design code
Controller:-
private List<Models.DepartmentModel> bindDepartment()
{
List<Models.DepartmentModel> deptList = new List<Models.DepartmentModel>();
SqlCommand com1 = new SqlCommand("sp_bindDepartment", con);
com1.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da1 = new SqlDataAdapter(com1);
DataTable ds1 = new DataTable();
da1.Fill(ds1);
for (int i = 0; i < ds1.Rows.Count; i++)
{
Models.DepartmentModel dm = new Models.DepartmentModel();
dm.deptId = ds1.Rows[i]["Id"].ToString();
dm.deptName = ds1.Rows[i]["deptName"].ToString();
deptList.Add(dm);
}
return deptList;
}
public ActionResult alumniSurvey()
{
ViewBag.deptList = bindDepartment();
return View();
}
[HttpPost]
public ActionResult alumniSurvery(FormCollection frm)
{
return View();
}
Please give any suggestion