Reputation: 104
I am trying to find ways to do multiple record update using foreach loop similar to snippet below. This snippet doesn't work on value type. If anyone would like to share their experience of multiple record update in MVC Framework. Thanks in advance
public ActionResult UpdateProductPrice()
{
var products = _rep.GetProducts();
foreach (Product p in products)
{
decimal oPrice = p.Price;
p.Price = oPrice * .15
UpdateModel(p);
_rep.Save();
}
return View("Index");
}
Upvotes: 2
Views: 964
Reputation: 7738
You are calling UpdateModel after you've changed p.Price. If the controller's current value provider has a property that maps to Price your changes will be lost during the UpdateModel call.
Upvotes: 1