What i'm trying to do: Try to delete a record using a "proper" HTTP Delete.
Controller Code:
[HttpDelete]
public void DeleteRun(int RunId)
{
repository.RemoveEntry(RunId);
}
Razor View:
@Ajax.ActionLink("Delete","DeleteRun",new {RunId = run.RunId},
new AjaxOptions() { Confirm = "Are you sure you want to delete this entry?",
HttpMethod = "DELETE",
OnComplete = string.Format("DeleteRunInTable({0})",run.RunId)
})
Javascript (in separate included file):
function DeleteRunInTable(RunId) {
$("tr[data-runid=" + RunId).remove();
}
Link the actionlink method is creating:
<a data-ajax="true" data-ajax-complete="DeleteRunInTable(11)" data-ajax-confirm="Are you sure you want to delete this entry?" data-ajax-method="DELETE" href="/Runs/Delete/11">Delete</a>
Not sure if the javascript part works yet but not to worried about it. Trying to take it one step at a time :). Now its just working like a traditional tag and when i click the link its just doing a GET request of the href. Of course i get a 404 error because of the [HTTPDelete] i put on my controller. I'm pretty new to web development so i'm sure there are other ways in either javascript or jquery to do the same thing but i'm just doing what i know at this point.