public ActionResult Create(PersonViewModel personViewModel) { if (ModelState.IsValid) { personViewModel.PersonDetail.Roles = new List <Capacity>(); foreach (var r in personViewModel.RolesSelected) { Capacity newRole = _repository.GetRoleById(Convert.ToInt16(r)); personViewModel.PersonDetail.Roles.Add(newRole); } _repository.CreatePerson(personViewModel.PersonDetail); return(RedirectToAction("Index")); } return(View(personViewModel)); }