public ActionResult Edit(CompetitionModel model) { if (ModelState.IsValid) { // Attempt to save the competition try { S_Competition competition = CompetitionManager.GetCompetition(model.Id); competition.challengeid = model.challengeId; competition.description = model.description; competition.enddate = model.EndDate; competition.startdate = model.StartDate; competition.price = model.price; competition.id = model.Id; CompetitionManager.Update(competition); CompetitionManager.DeleteAllBowlingCentersByCompetition(competition.id); // setup properties var selectedBowlingCenters = new List <C_Checkbox>(); var postedBowlingCenterIds = new string[0]; if (model.PostedBowlingCenters == null) { model.PostedBowlingCenters = new C_PostedCheckbox(); } // if a view model array of posted ids exists // and is not empty, save selected ids if (model.PostedBowlingCenters.CheckboxIds != null && model.PostedBowlingCenters.CheckboxIds.Any()) { postedBowlingCenterIds = model.PostedBowlingCenters.CheckboxIds; foreach (var id in postedBowlingCenterIds) { CompetitionManager.InsertBowlingcenterForCompetition(competition.id, long.Parse(id)); } } TempData["message"] = "De competitie met nummer " + competition.id + " is aangepast."; return(RedirectToAction("competition", "Competition", new { id = model.challengeId })); } catch (Exception e) { TempData["error"] = "Er is een fout opgetreden"; } } // If we got this far, something failed, redisplay form return(View(model)); }