public async Task <ActionResult> EditClass(ClassEditViewModel model) { var departments = await InstitutionManager.GetAllDepartmentsAsync(); SelectList departSelectList = new SelectList(departments.ToList(), "Id", "Name"); ViewBag.departSelectList = departSelectList; var majors = await InstitutionManager.GetMajorsForDepartmentAsync(departments.ElementAtOrDefault(0)); SelectList majorSelectList = new SelectList(majors.ToList(), "Id", "Name"); ViewBag.majorSelectList = majorSelectList; var grades = await InstitutionManager.GetAllGradesAsync(); SelectList gradeSelectList = new SelectList(grades.ToList(), "Id", "GradeNum"); ViewBag.gradeSelectList = gradeSelectList; ViewBag.Classes = await InstitutionManager.GetAllClassesAsync(); if (ModelState.IsValid) { var class1 = await InstitutionManager.FindClassByIdAsync(model.Id); if (class1 == null) { ModelState.AddModelError("", "找不到class1"); return(View(model)); } var grade = await InstitutionManager.FindGradeByIdAsync(model.GradeId); if (grade == null) { ModelState.AddModelError("", "找不到grade"); return(View(model)); } var major = await InstitutionManager.FindMajorByIdAsync(model.MajorId); if (major == null) { ModelState.AddModelError("", "找不到major"); return(View(model)); } class1.Major = major; class1.Grade = grade; class1.ClassDefination = model.Defination; await InstitutionManager.UpdateClassAsync(class1); await UserManager.RemoveStudentsFromClassAsync(model.IdsToRemove ?? new string[] { }); return(RedirectToAction("AllClass")); } return(View(model)); }