9.1: NoteEdit View
Create the Edit View
Edit ViewEdit Post Method
Edit Post Method[HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit(int id, NoteEdit model) { return View(); }[HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit(int id, NoteEdit model) { if(!ModelState.IsValid) return View(model); if(model.NoteId != id) { ModelState.AddModelError("", "Id Mismatch"); return View(model); } return View(); }[HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit(int id, NoteEdit model) { if(!ModelState.IsValid) return View(model); if(model.NoteId != id) { ModelState.AddModelError("", "Id Mismatch"); return View(model); } var service = CreateNoteService(); if (service.UpdateNote(model)) { TempData["SaveResult"] = "Your note was updated."; return RedirectToAction("Index"); } ModelState.AddModelError("", "Your note could not be updated."); return View(model); }
Remove NoteId from the Edit View
NoteId from the Edit ViewLast updated
