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)
{
开发者_JAVA百科 SetupDropDownsStronglyTyped(raceViewModel);
return View(raceViewModel);
}
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
).
精彩评论