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 KumarPosted Feb 2, 2017, 11:57 PM
Rahul MittalPosted Feb 2, 2017, 7:02 AM
But i am confused that use of session to create a list is a good option or not.
Rahul MittalPosted Feb 1, 2017, 7:36 AM
Amit KumarPosted Jan 30, 2017, 12:33 AM
Bikesh SrivastavaPosted Jan 29, 2017, 10:32 AM