I'm following Stephen Walther's tutorial on safely deleting via POST + AJAX (found here: http://stephenwalther.com/blog/archive/2009/01/21/asp.net-mvc-tip-46-ndash-donrsquot-use-delete-links-because.aspx), but am having problems he did not mention in his article.
I modified his code slightly, so that I have an Index.aspx file which contains a Movies.ascx partial view. The partial view is strongly typed, and is where my delete link lives. The delete logic is as such:
public ActionResult Delete(int id)
{
var movieToDelete = (from m in _entities.MovieSet
where m.Id == id
select m).FirstOrDefault();
_entities.DeleteObject(movieToDelete);
_entities.SaveChanges();
return RedirectToAction("Index");
}
When a delete link is clicked, Delete is called, the object is deleted, and RedirectToAction returned. However, the page doesn't update. If you click the link again, an exception is thrown (since the object with that ID is already deleted), and the page updates. Remembering I was working with partials, I changed the return to
return PartialView();
thinking it would fix the problem, but it had no effect. The object is still deleted and the page never refreshed.
I'm stumped - not sure where the problem is at this point, seems to be a something wrong with my return, but I'm not sure.