Ok i have an mvc app. and im trying to get my delete to work. Basically i want it so when i click delete it takes me to a page saying "are you sure?" i have that working, the problem is catching the request and actually doing the delete. i tried diffrent methods. as below.
public ActionResult Delete(int id)
{
var something = friendsDB.Friends.Single(a => a.Id == id);
return View(something);
}
[HttpPost]
public ActionResult Delete(int id, string confirmButton)
{
var something = friendsDB.Friends.Single(a => a.Id == id);
// For simplicity, we're allowing deleting of albums
// with existing orders We've set up OnDelete = Cascade
// on the Album->OrderDetails and Album->Carts relationships
friendsDB.DeleteObject(something);
friendsDB.SaveChanges();
return View("Index");
}
That doesnt work cause, deleteobject and savechanges claim
"C:\Users\Mtszc\Documents\Visual Studio 2010\Projects\Test\Test\Content\Controllers\DownloadsController.cs(36,23): error CS1061: 'Test.Models.FriendsDB' does not contain a definition for 'DeleteObject' and no extension method 'DeleteObject' accepting a first argument of type 'Test.Models.FriendsDB' could be found (are you missing a using directive or an assembly reference?)"
the second thing i tried was
public ActionResult Delete(int id)
{
var something = friendsDB.Friends.Single(a => a.Id == id);
return View(something);
}
[HttpDelete]
public ActionResult Delete(Friend myFriend)
{
try
{
friendsDB.Friends.DeleteOnSubmit(myFriend);
friendsDB.SubmitChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
that didnt work. it compiled but when i click delete, and it takes me to the page where i say im sure i want to delete, it returns view, which was the catch, meaning the try failed.
this is a simple sql database i made, Id, name, link. and im using linq to sql class. i c can create and view, but not delete.