There is no ViewData item with the key 'Student-Id' of type IEnumerable<SelectListItem>
I got the above error when I wrote below code to bind data in DropdownList.
In View
I got the above error when I wrote below code to bind data in DropdownList.
In View
<%= Html.DropDownListFor(x =>.Student_Id,<SelectList>ViewData["StudentList"])%>
In Controller
TestMVCEntities3 DBobj = new TestMVCEntities3();
ViewData["StudentList"] = new SelectList(DBobj.Student, "Student_Id","Name");
return View();
I Resolved the above error by Using Model instead of ViewData in below manner
In View
<%= Html.DropDownListFor(x => x.Student_Id,Model.StudentList)%>
In Model
public IEnumerable<SelectListItem> StudentList { get; set; }
In Controller
TestMVCEntities3 DBobj = new TestMVCEntities3();
var model = new StudentMarksModel();
model.StudentList = new SelectList(DBobj.Student, "Student_Id", "Name");
return View(model);
where does x in View come from?
ReplyDelete