public ActionResult Edit(TouristAttraction touristattraction) { if (ModelState.IsValid) { db.Entry(touristattraction).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(touristattraction)); }
public ActionResult Edit(Review review) { if (ModelState.IsValid) { db.Entry(review).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TouristAttractionId = new SelectList(db.TouristAttractions, "TouristAttractionId", "Name", review.TouristAttractionId); return(View(review)); }
// The id parameter name should match the DataKeyNames value set on the control public void attractionsForm_UpdateItem([RouteData] int?id) { MvcApplication2.Models.TouristAttraction item = db.TouristAttractions.Find(id); // Load the item here, e.g. item = MyDataLayer.Find(id); if (item == null) { // The item wasn't found ModelState.AddModelError("", String.Format("Item with id {0} was not found", id)); return; } TryUpdateModel(item); if (ModelState.IsValid) { // Save changes here, e.g. MyDataLayer.SaveChanges(); db.Entry(item).State = EntityState.Modified; db.SaveChanges(); } }