// GET: /Product/Delete/5
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();
}
}
}
Here in the line “producttodelete” i am not getting any values it is cuming null.Rather than create,details,edit are working fine…. only delete not working…….I tried a lot
Assuming you are using strongly typed views, have you tried:
… or if you are not using strongly typed views:
In either case, you need to provide an
idparameter which you can then use to get your object from your datastore. The default route mapping in MVC2 (in Global.asax.cs) will take the ID from the post URL and map it to this parameter for you.