0
Answer

how to save and update a record using the same view

Uvie Jakpor

Uvie Jakpor

9y
552
1
hello guys,am working on an online admission system where i store records of students in my database.
i have a form where i want to implement a save and update record in the same view insteasd of passing the values to another view for update..here is my code below




 if (ModelState.IsValid)
            {
                student = db.Students.Find(student.ID);
                if (student == null)
                {

                    db.Students.Add(student);
                }
                else
                {

                    db.Entry(student).State = EntityState.Modified;
                  
                }
                db.SaveChanges();