Error Type:
There is no ViewData item of type 'IEnumerable' that has the key 'Course_ID'.
Hi Everyone i am facing a problem as above using asp.net MVC4 technology.
Controller:
[HttpGet]
public ActionResult Register(int id)
{
Student_Mgt student = new Student_Mgt(); IEnumerable 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 , "Select Course" ,new {@id="courses",@class="form-control"})

Amit KumarRank #459 · 5.4K reputationPosted Feb 2, 2017, 6:57 PM EST
Rahul Mittal12 reputationPosted Feb 2, 2017, 2:02 AM EST
But i am confused that use of session to create a list is a good option or not.
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Jan 29, 2017, 5:32 AM EST
Amit KumarRank #459 · 5.4K reputationPosted Jan 29, 2017, 7:33 PM EST
Rahul Mittal12 reputationPosted Feb 1, 2017, 2:36 AM EST