// GET:/產品/刪除/ 5刪除所有未在MVC工作2
public ActionResult Delete(int id)
{
var res = (from r in data.Products where r.ProductID == id select r).FirstOrDefault();
//return View(data.Products.FirstOrDefault(p => p.ProductID == id));
return View(res);
}
//
// POST: /Product/Delete/5
// [HttpPost]
[AcceptVerbs(HttpVerbs.Post)]
**public ActionResult Delete(Product producttodelete)**
{
try
{
// TODO: Add delete logic here
var res = (from r in data.Products where r.ProductID == producttodelete.ProductID select r).FirstOrDefault();
// var productto = data.Products.Single(p => p.ProductID == producttodelete.ProductID);
data.Products.DeleteObject(res);
data.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
在這裏,在行 「producttodelete」 我沒有得到它比創造,細節卡明null.Rather任何值,編輯工作正常....只刪除不工作.......我試了很多
,而過路data.savechanges我得到這個錯誤( 「在更新條目時發生錯誤,請參閱內部異常以瞭解詳細信息)在catch塊 – 2010-11-12 08:43:59
@Karthik所以什麼是內部異常? – Graham 2010-11-12 08:45:34
public ActionResult Delete(int id) {var res =(from r in data.Products where r .ProductID == id select r).FirstOrDefault(); return View(res);} [AcceptVerbs(HttpVerbs.Post)] public ActionResult Delete(int id,FormCollection collection) { 嘗試 {var res =(from r in data.Products where r.ProductID == id select r).FirstOrDefault(); data.Products.DeleteObject(res); data.SaveChanges(); 返回RedirectToAction(「指數」);} 抓 {返回查看();} } – 2010-11-12 08:57:19