Dave Mateer
Dave Mateer

Reputation: 6626

ModelState refresh in post to remove errors

Problem: ModelState is not valid, complaining that there is no Event.

I've tried associating it and done a TryUpdateModel

Inspecting raceViewModel it does look fine.

 [HttpPost]
    public ActionResult Create(RaceViewModel raceViewModel, Guid idEvent)
    {
        Event _event = uow.Events.Single(e => e.Id == idEvent);
        raceViewModel.RaceInVM.EventU = _event;
        TryUpdateModel<RaceViewModel>(raceViewModel);

        if (!ModelState.IsValid)
        {
            SetupDropDownsStronglyTyped(raceViewModel);
            return View(raceViewModel);
        }

Upvotes: 1

Views: 1008

Answers (1)

Ronald Wildenberg
Ronald Wildenberg

Reputation: 32094

I think that your idEvent parameter may not be what you expect it to be. The uow.Events.Single call then fails and throws an exception (there is no Event with the provided Id).

Upvotes: 1

Related Questions