Click Here For MCQ

Friday, June 26, 2020

Update and Edit entityframework asp.net mvc

public class HomeController : Controller
    {
        StudentContext db = new StudentContext();
        // GET: Home
        public ActionResult Index()
        {
            var ad =db.Students.ToList();
            return View(ad);
        }

        public ActionResult edit(int id = 0)
        {
            var data = db.Students.Where(m => m.StudentId == id).FirstOrDefault();
            return View(data);
        }
        [HttpPost]
        public ActionResult edit(Student s)
        {
            db.Entry(s).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }

No comments:

Post a Comment