public ActionResult Edit(int id) { using (var ctx = new Context()) { var c = ctx.Contents.FirstOrDefault(x => x.Id == id); var model = new ContentCreateModel { Id = c.Id, Name = c.Name, Text = c.Text }; return View(model); } }
public ActionResult Edit(ContentCreateModel post) { if (this.ModelState.IsValid) { using (var ctx = new Context()) { var c = ctx.Contents.FirstOrDefault(x => x.Id == post.Id); c.Text = post.Text; c.Name = post.Name; } return RedirectToAction("Index"); } return View(); }