public ActionResult Index(IndexVM a) { var b = (IndexVM)TempData["list"]; if (b.ListofIndex.Count == 0) { b.sec = a.sec; b.Sem = a.Sem; b.SectionList = GetSectionList(a.Deptlist,a.Sem); b.Deptlist = a.Deptlist; var late = db.Subjects.Where(x => x.Sem == b.Sem).Select(x => new { Text = x.DeptId, Value = x.DeptId }).ToList(); late = late.GroupBy(x => x.Text).Select(x => x.First()).ToList(); b.SubjectDeptList = new SelectList(late, "Value", "Text").ToList(); b.SubjectDeptList.Add(new SelectListItem { Text = "Select Subject Department", Value = "0", Selected = true }); b.Semester = Semmanu(b.Deptlist); } if (ModelState.IsValid) { a.TeacherName = db.Teachers.Find(a.TID).TeacherName; a.SubjectName = db.Subjects.Find(a.subcode).SubName; int l = 1; //add the element to the list foreach(var i in b.ListofIndex) { if(i.sec==a.sec && i.Sem==a.Sem &&i.subcode==a.subcode&&a.TID==a.TID) { l = 2; break; } } if (l != 2) { b.ListofIndex.Add(a); b.subcode = "0"; b.TID = "0"; b.SDept = "0"; b.Tdept = "0"; } } else { //for listing copy content of b to a i.e. ListOfIndex value b.Tdept = a.Tdept; b.SDept = a.Tdept; b.TID = a.TID; b.sec = a.sec; b.subcode = a.subcode; ModelState.AddModelError(String.Empty, "PLEASE ENTER ALL THE FIELD"); } b.sec = a.sec; TempData["list"] = b; return View(b); }
public ActionResult Index() { TempData["list"] = null; IndexVM dept = new IndexVM(); dept.DepartmentList = GetDepat(); dept.TeacherDetail = GetDepat(); TempData["list"] = dept; return View(dept); }