public ActionResult Edit(int id, ContactEditModels obj) { try { PhoneBookDbEntities db = new PhoneBookDbEntities(); db.Contacts.Find(id).ContactNumber = obj.ContactNumber; db.Contacts.Find(id).Type = obj.Type; db.SaveChanges(); // TODO: Add update logic here return(RedirectToAction("Create", "ContactView")); } catch { return(View()); } }
// GET: ContactView/Edit/5 public ActionResult Edit(int id) { PhoneBookDbEntities db = new PhoneBookDbEntities(); ContactEditModels c = new ContactEditModels(); foreach (Contact a in db.Contacts) { if (a.ContactId == id) { c.ContactNumber = a.ContactNumber; c.Type = a.Type; break; } } return(View(c)); }