Problem: How to get rid of the event drop down?
When I comment it out in the view I get Model validation errors. It doesn't know which Event to associate it with. Even though I'd told it in the create action - as shown because it has selected the correct drop down option.
public ActionResult Create(Guid idEvent)
{
ViewBag.EventName = uow.Events.Single(e => e.Id == idEvent).Name;
RaceViewModel racesViewModel = new RaceViewModel();
SetupDropDownsStronglyTyped(racesViewModel);
Race race = new Race();
racesViewModel.RaceInVM = race;
Event _event = uow.Events.Single(e => e.Id == idEvent);
racesViewModel.RaceInVM.EventU = _event;
return View(racesViewModel);
}
view
<div class="editor-field">
@Html.DropDownListFor(x => x.RaceInVM.EventUId, new SelectList(Model.ListOfEvents, "Id", "Name"))
post:
[HttpPost]
public ActionResult Create(RaceViewModel raceViewModel, Guid idEvent)
{
if (!ModelState.IsValid)
{
SetupDropDownsStronglyTyped(raceViewModel);
return View(raceViewModel);
}
uow.Add(raceViewModel.RaceInVM);
uow.SaveChanges();
return RedirectToAction("Index");
}