public ActionResult Create([Bind(Include = "StudentAttendence")] ViewStudentAttendence objViewStudentAttendence) { if (ModelState.IsValid) { if (objViewStudentAttendence.StudentAttendence.TotalPresentStudent > objViewStudentAttendence.StudentAttendence.TotalStudent) { TempData["Message"] = "Pls Enter Total valid Present Student!!"; return(RedirectToAction("Create")); } if (objViewStudentAttendence.StudentAttendence.PresentFemaleStudent > objViewStudentAttendence.StudentAttendence.FemaleStudentNo) { TempData["Message"] = "Pls Enter Valid Present Female Student"; return(RedirectToAction("Create")); } db.StudentAttendences.Add(objViewStudentAttendence.StudentAttendence); db.SaveChanges(); return(RedirectToAction("Create")); } var students = db.StudentAttendences.Where(x => x.DateTime.Year == DateTime.Now.Year && x.DateTime.Month == DateTime.Now.Month && x.DateTime.Day == DateTime.Now.Day).ToList(); // ViewBag.StudentList = students; change here objViewStudentAttendence.StudentAttendenceList = students; objViewStudentAttendence.Class = new SelectList(db.ClassOrYears, "Code", "Name", objViewStudentAttendence.StudentAttendence); return(View(objViewStudentAttendence)); }
// GET: StudentAttendence/Create public ActionResult Create() { ViewStudentAttendence objViewStudentAttendence = new ViewStudentAttendence(); objViewStudentAttendence.Class = new SelectList(db.ClassOrYears, "Code", "Name"); var students = db.StudentAttendences.Where(x => x.DateTime.Year == DateTime.Now.Year && x.DateTime.Month == DateTime.Now.Month && x.DateTime.Day == DateTime.Now.Day).ToList(); // ViewBag.StudentList = students; change here.... // StudentAttendenceList Declare ViewStudentAttendence(View Models) objViewStudentAttendence.StudentAttendenceList = students; return(View(objViewStudentAttendence)); }