// GET: CRUD/Delete/5 public ActionResult Delete(int Studentid) { using (var context = new StudentCRUDEntities()) { var data = context.Students.Where(x => x.StudentNo == Studentid).SingleOrDefault(); return(View(data)); } }
public ActionResult Read() { using (var context = new StudentCRUDEntities()) { var data = context.Students.ToList(); return(View(data)); } }
public ActionResult Create(Student model) { using (var context = new StudentCRUDEntities()) { context.Students.Add(model); context.SaveChanges(); return(RedirectToAction("Read")); } // string message = "Created the record successfully"; // ViewBag.Message = message; }
public ActionResult Delete(int Studentid, Student model) { using (var context = new StudentCRUDEntities()) { var data = context.Students.FirstOrDefault(x => x.StudentNo == Studentid); if (data != null) { context.Students.Remove(data); context.SaveChanges(); return(RedirectToAction("Read")); } else { return(View()); } } }
public ActionResult Update(int Studentid, Student model) { using (var context = new StudentCRUDEntities()) { var data = context.Students.FirstOrDefault(x => x.StudentNo == Studentid); if (data != null) { data.Name = model.Name; data.Section = model.Section; data.EmailId = model.EmailId; data.Branch = model.Branch; context.SaveChanges(); return(RedirectToAction("Read")); } else { return(View()); } } }