2

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");
}
1
  • can you please elaborate moore on this " This snippet doesn't work on value type" Commented Nov 26, 2010 at 5:05

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.