public ActionResult Create(FormCollection f) { try { PhoneBookDbEntities db = new PhoneBookDbEntities(); ContactCreateModels con = new ContactCreateModels(); var model = new List <ContactCreateModels>(); foreach (Contact c in db.Contacts) { if (c.PersonId == Meduim.MediumData) { con.ContactNumber = c.ContactNumber; con.Type = c.Type; con.PersonId = c.PersonId; con.ContactId = c.ContactId; model.Add(con); } } return(View(model)); // TODO: Add insert logic here } catch { return(View()); } }
// GET: ContactView/Create public ActionResult Create() { PhoneBookDbEntities db = new PhoneBookDbEntities(); var model = new List <ContactCreateModels>(); foreach (Contact c in db.Contacts) { if (c.PersonId == Meduim.MediumData) { ContactCreateModels con = new ContactCreateModels(); con.ContactNumber = c.ContactNumber; con.Type = c.Type; con.PersonId = c.PersonId; con.ContactId = c.ContactId; model.Add(con); } } return(View(model)); }
public ActionResult Create(ContactCreateModels obj) { try { Contact c = new Contact(); c.ContactNumber = obj.ContactNumber; c.Type = obj.Type; c.PersonId = Meduim.MediumData; PhoneBookDbEntities db = new PhoneBookDbEntities(); db.Contacts.Add(c); db.SaveChanges(); return(RedirectToAction("Create", "ContactView", new { id = Meduim.MediumData })); // TODO: Add insert logic here } catch { return(View()); } }