public ActionResult Edit([Bind(Include = "Id,Student_Id,SubjectId")] SubjectAssignVM subjectAssignVM) { if (ModelState.IsValid) { StudentSubject studentSubject = db.StudentSubjects .FirstOrDefault(s => s.Id == subjectAssignVM.Id); studentSubject.StudentId = subjectAssignVM.StudentId; studentSubject.SubjectId = subjectAssignVM.SubjectId; db.Entry(studentSubject).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StudentId = new SelectList(db.Students, "Id", "Student_Id", subjectAssignVM.StudentId); ViewBag.SubjectId = new SelectList(db.Subjects, "Id", "SubjectName", subjectAssignVM.SubjectId); return(View(subjectAssignVM)); }
// GET: SubjectAssign/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // db.StudentSubjects.Find(id); SubjectAssignVM subjectAssignVM = new SubjectAssignVM(); if (subjectAssignVM == null) { return(HttpNotFound()); } ViewBag.StudentId = new SelectList(db.Students, "Id", "Student_Id", subjectAssignVM.StudentId); ViewBag.SubjectId = new SelectList(db.Subjects, "Id", "SubjectName", subjectAssignVM.SubjectId); return(View(subjectAssignVM)); }