I've successfully selected the Objects I want to delete. But the problem is when I remove an item from Object array, it doesn't make any changes. My code is following below..
My database
public List<Product> db = new ProductRepository().GetProducts();
Here it shows all the products with checkbox..
public ActionResult MultipleDeletes()
{
return View(db);
}
On Submitting "Button named Delete", I got problem.
[HttpPost]
public ActionResult MultipleDeletes(int[] selectedProducts)
{
var del_products = from x in selectedProducts
from y in db
where y.ProductId == x
select y;
foreach (var item in del_products)
{
//Product p = db.Find(item.ProductId);
//db.Remove(p);
//db.SaveChanges();
}
return View(db);
}
Could anyone help me? can you also tell me, how to write Lambda expression instead of LinQ?