Hi
I'm using the NerdDinner MVC1 code. Created a viewmodel called DinnerFormViewModel:
public class DinnerFormViewModel
{
public Dinner Dinner { get; private set; }
public SelectList Countries { get; private set; }
public DinnerFormViewModel(Dinner dinner)
{
Dinner = dinner;
Countries = new SelectList(PhoneValidator.Countries, dinner.Country);
}
}
I pass to my edit view fine which uses strongly typed helpers in MVC2. Passing back however:
public ActionResult Edit(int id, FormCollection collection)
{
Dinner dinnerToUpdate = dr.GetDinner(id);
try
{
UpdateModel(dinnerToUpdate, "Dinner"); // using a helper becuase of strongly typed helpers to tell it what to update
// updates the properites of the dinnerToUpdate object using incoming form parameters collection.
// UpdateModel automatically populates ModelState when it encounters errors
// works by when trying to assign BOGUS to a datetime
// dinnerToUpdate.Country = Request.Form["Countries"];
dr.Save(); // dinner validation may fail here too due to hook into LINQ to SQL via Dinner.OnValidate() partial method.
return RedirectToAction("Details", new { id = dinnerToUpdate.DinnerID });
}
This works, however my Country doesn't get updated, becuase I'm only giving the hint to UpdateModel to update the Dinner.
Question: How to get the country saving?
Thanks.