public ActionResult AddUsersToExam(FormCollection fm) { var selectedusers = fm["SelectedUsers"]; var examId = int.Parse(fm["ExamId"]); var exam = _examinationRepository.GetExaminationData(examId); var preSelected = exam.Members.ToList(); if (preSelected.Any()) { _examinationRepository.DetachMembersFromExam(examId); } if (selectedusers.Length > 1) { _examinationRepository.AttachMembersToExam(selectedusers, examId); } TempData["notification"] = "The Users have been successfully added/detached"; return(RedirectToAction("AddUsersToExam", new { examId })); }