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

Railway RRB Station Master Online Form 2026 Book

Railway RRB Station Master Online Form 2026 BOOK Book Link BUY NOW The Railway Recruitment Board (RRB) has officially issued the Centralise...