public ActionResult IndexUniver() { UniverContext uc = new UniverContext(); ViewBag.Students = uc.Students.ToList(); ViewBag.Courses = uc.Courses.ToList(); return View(); }
public ActionResult StudentEdit(Student st, int[] selectedCourses) { UniverContext uc = new UniverContext(); uc.Entry(st).State = EntityState.Modified; uc.SaveChanges(); return RedirectToAction("StudentDetails",new { id = st.Id}); }
public ActionResult StudentDetails(int? Id) { UniverContext uc = new UniverContext(); Student st = uc.Students.Find(Id); return View(st); }
public ActionResult StudentEdit(int? Id) { UniverContext uc = new UniverContext(); EditModel em = new EditModel(); em.Courses = sl(uc); em.Student = uc.Students.Find(Id); ViewBag.UC = new MultiSelectList(uc.Courses.Select(c => new { Name = c.Name }).ToList(),"Name"); return View(em); }
public IEnumerable<SelectListItem> sl(UniverContext uc_) { List<SelectListItem> sellist = new List<SelectListItem>(); foreach(Course cs in uc_.Courses) { sellist.Add(new SelectListItem { Text = cs.Name }); } return sellist; }