What is the best way to delete an item in MVC? I have a list of items. Each row will contain a "Delete" link. I want the Delete link to prompt for confirmation, then delete the item from the datastore and refresh the page with the new data.
Here is my view code:
<%: Ajax.ActionLink(
"Delete"
,"Delete"
, new { id=item.FooId}
, new AjaxOptions()
{
Confirm="Are you sure that you want to delete this item?"
, HttpMethod = "post"} ) %>
And here is my controller code:
[HttpPost]
public ActionResult Delete(int id)
{
try
{
var success = FooService.Deletefoo(id);
return RedirectToAction("Index");
}
catch
{
return View();
}
}
The record is being deleted, however the page is not refreshing. The only thing that I can think of is that RedirectToAction only works for different pages, not the same page.
How do I get the page to refresh? Thanks.