public ActionResult AddReportingTeamMember(AddRepoToTeamMemberViewModel model) { try { if (ModelState.IsValid) { if (model.RepoToIds != null && model.RepoToIds.Count() > 0) { repoTeamMember.AddRepoToTeamMember(model); int Res = repoTeamMember.SaveChanges(); if (Res > 0) { TempData["SuccessMsg"] = "Record Added Successfully!"; ModelState.Clear(); return(RedirectToAction("ManageReportedTeamMembers", new { tdid = model.TeamDepartmentRowID })); } else { TempData["ErrorMsg"] = "There is no change!"; return(RedirectToAction("ManageReportedTeamMembers", new { tdid = model.TeamDepartmentRowID })); } } else { ModelState.AddModelError("", "TeamMember Name could not be blank!"); } } else { var query = from state in ModelState.Values from error in state.Errors select error.ErrorMessage; var errorList = query.ToList(); string strError = string.Empty; foreach (string str in errorList) { strError += str + "\n"; } ModelState.AddModelError("", strError); } } catch (Exception Ex) { ViewBag.ErrorMsg = Ex.Message; } BindRepoToTeamMemberList(model.TeamDepartmentRowID); return(View(model)); }