public ActionResult Create(PersonFormViewModel viewModel) { //var gender = _context.Genders.Single(g => g.Id == viewModel.GenderId); if (!ModelState.IsValid) { viewModel.Genders = _context.Genders.ToList(); return(View("Create", viewModel)); } var contact = new Person { FirstName = viewModel.FirstName, LastName = viewModel.LastName, DateOfBirth = viewModel.GetDateOfBirth(), GenderId = viewModel.GenderId }; _context.Contacts.Add(contact); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }