public ActionResult Create([Bind(Include = "Id,PhoneTypeId,PhoneNumber,ClientId")] Phone phone) { if (ModelState.IsValid) { db.Phones.Add(phone); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ClientId = new SelectList(db.Clients, "Id", "Name", phone.ClientId); return(View(phone)); }
public ActionResult Create(ClientViewModel model) { if (ModelState.IsValid) { var client = new Client(); client.Name = model.Name; client.DateOfBirth = model.DateOfBirth; client.Rg = model.Rg; client.Cpf = model.Cpf; db.Clients.Add(client); db.SaveChanges(); return(RedirectToAction("Index")); } // Se ocorrer um erro retorna para pagina ViewBag.Clients = db.Clients; return(View(model)); }