I am trying to update model from the FormCollection for two distinct collections of model. IT only works for the first time. Here is the sample code:
public ActionResult Edit(int id, FormCollection form)
{
Order ord = pr.GetOrder(id);
TryUpdateModel<Order>(ord, form.ToValueProvider());
IEnumerable<OrderItem> items = new List<OrderItem>();
IEnumerable<OrderPayment> pmts = new List<OrderPayment>();
/* 1. */ TryUpdateModel<IEnumerable<OrderItem>>(items, "oitm", form.ToValueProvider());
/* 2. */ TryUpdateModel<IEnumerable<OrderPayment>>(pmts, "opmt", form.ToValueProvider());
//Save the model
return PartialView("IndexItem", inv);
}
It populates the model for Order and items, but does not update pmts collection from formcollection. I checked the form collection and it does have all the properties for the opmt prefix. If I switch the TryUpdateModel between 1 and 2 then it updates the pmts successfully and not the items.
My assumptions are as follows:
- It may be something to do with multiple TryUpdateModel on a collection.
- Once I get the ModelState Error then it will not update following try to update model
What am I doing wrong here???
THIS SAME CODE and MODELS were WORKING FOR MVC2!
Thanks
GREAT!
RTM release of MVC3 has fixed this issue. So looks like it was bug but no one acknowledged it. Anyways its fixed.
Great release, Thanks to MVC team.