开发者

ModelState refresh in post to remove errors

开发者 https://www.devze.com 2023-02-28 12:58 出处:网络
Problem:ModelState is not valid, complaining that there is no Event. I\'ve tried associating it and done a TryUpdateModel

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消