日期:2014-05-18 浏览次数:21229 次
private MagicShopEntities entities = new MagicShopEntities(); public ActionResult Delete(int id) { var productToDelete = (from p in entities.Product where p.ProductId == id select p).First(); return View(productToDelete); } // // POST: /Product/Delete/5 [AcceptVerbs(HttpVerbs.Post)] public ActionResult Delete([Bind(Exclude = "ProductId")] Product productToDelete) { try { if (!ModelState.IsValid) { return View(); } entities.Delete(productToDelete) //entities不包含Delete的定义。 entities.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }