public ActionResult EditProperty(int id) { using (var db = new ApplicationDbContext()) { var address = db.Properties.FirstOrDefault(x => x.Id == id); if (address == null) { return(HttpNotFound()); } var model = new PropertyEditModel { Id = address.Id, Address = address.Address }; return(View(nameof(EditProperty), model)); } }
public ActionResult EditProperty(int id, PropertyEditModel model) { if (ModelState.IsValid) { using (var db = new ApplicationDbContext()) { var property = db.Properties.FirstOrDefault(x => x.Id == model.Id); if (property == null) { return(HttpNotFound()); } property.Address = model.Address; db.SaveChanges(); } return(RedirectToAction(nameof(ListProperties))); } return(View(nameof(EditProperty), model)); }