TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rahul Mittal
NA
10
770
List Doesn't Working in asp.net mvc4
Jan 29 2017 5:28 AM
Error Type:
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.
Controller:
[HttpGet]
public ActionResult Register(int id)
{
Student_Mgt student = new Student_Mgt();
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"})
Reply
Answers (
5
)
Deplying asp.net project
Editable Responsive Gridview in asp.net