public ActionResult Edit(EditNoteViewModel model) { if (!ModelState.IsValid) { return View(); } notes.Update(model.Note); notes.SaveChanges(); notes.Dispose(); return RedirectToAction("Index"); }
public ActionResult Edit(int Id) { var note = notes.Where(p => p.Id == Id).FirstOrDefault(); if (note == null || note.UserId != User.Identity.GetUserId() ) { throw new HttpException("Requested note not found."); } // create a viewmodel so the user has some dropdown lists var viewModel = new EditNoteViewModel { Note = note, SelectedType = note.NoteTypeId, Types = types.GetAll().Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name, Selected = (note.NoteTypeId == x.Id) }) }; return PartialView("_Edit", viewModel); }