I suggest that if you need something like this for an Action that will do something โpersistentโ on the server side. For example, deleting an object in a database.
Here is a complete removal example using the link and publication: http://www.squarewidget.com/Delete-Like-a-Rock-Star-with-MVC3-Ajax-and-jQuery
From the previous link (recommended reading anyway):
Delete link in your opinion:
@Ajax.ActionLink("Delete", "Delete", "Widget", new {id = item.Id}, new AjaxOptions { HttpMethod = "POST", Confirm = "Are you sure you want to delete this widget?", OnSuccess = "deleteConfirmation" })
A bit of JS:
function deleteConfirmation(response, status, data) { // remove the row from the table var rowId = "#widget-id-" + response.id; $('.widgets').find(rowId).remove(); // display a status message with highlight $('#actionMessage').text(response.message); $('#actionMessage').effect("highlight", {}, 3000); }
source share