title: Getting MVC2 Delete to work
body: <p>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.</p>
  
  <pre><code> public ActionResult Delete(int id)
      {
          var something = friendsDB.Friends.Single(a =&gt; a.Id == id);
          return View(something);
      }
      [HttpPost]
      public ActionResult Delete(int id, string confirmButton)
      {
          var something = friendsDB.Friends.Single(a =&gt; a.Id == id);
  
          // For simplicity, we're allowing deleting of albums
          // with existing orders We've set up OnDelete = Cascade
          // on the Album-&gt;OrderDetails and Album-&gt;Carts relationships
  
          friendsDB.DeleteObject(something);
          friendsDB.SaveChanges();
  
          return View("Index");
      }
  </code></pre>
  
  <p>That doesnt work cause, deleteobject and savechanges claim </p>
  
  <blockquote>
    <p>"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?)"</p>
  </blockquote>
  
  <p>the second thing i tried was </p>
  
  <pre><code>public ActionResult Delete(int id)
      {
          var something = friendsDB.Friends.Single(a =&gt; 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();
          }
      }
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>