public ActionResult Create(Contact contact) { if (!ModelState.IsValid) { return View(contact); } using (ContactContext context = new ContactContext()) { context.Contacts.Add(contact); context.SaveChanges(); } return this.RedirectToAction("List"); }
// GET: /Contact/List public ActionResult List(string searchQuery) { IEnumerable<Contact> contacts; using (ContactContext context = new ContactContext()) { if (!string.IsNullOrEmpty(searchQuery)) { contacts = context.SearchContacts(searchQuery).ToList(); } else { contacts = context.Contacts.ToList(); } } return View(contacts); }