There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Course_ID'.
Hi Everyone i am facing a problem as above using asp.net MVC4 technology.
IEnumerable<SelectListItem> list = new SelectList(db.Courses.ToList(), "Course_ID", "Course_Name");
ViewBag.SelectCourses = list;
return View(student);
}
[HttpPost]
[ActionName("Register")]
public ActionResult RegisterPost(Student_Mgt Student)
{
if (ModelState.IsValid)
{
db.Student_Mgt.Add(Student);
db.SaveChanges();
return RedirectToAction("List_Enquiries", "Main");
}
else
{
return View();
}
}
View
@Html.DropDownListFor(m=>m.Course_ID,ViewBag.SelectCourses as IEnumerable<SelectListItem>, "Select Course" ,new {@id="courses",@class="form-control"})