What I'm trying to do: Try deleting the entry using the "correct" HTTP deletion.
Controller Code:
[HttpDelete] public void DeleteRun(int RunId) { repository.RemoveEntry(RunId); }
Shaver Type:
@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 a separate file):
function DeleteRunInTable(RunId) { $("tr[data-runid=" + RunId).remove(); }
A link to the actionlink method creates:
<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 part of javascript is working, but not worried about it. Trying to do it step by step :). Now it just works like a traditional tag, and when I click the link, I just execute the href GET request. Of course, I get a 404 error due to the fact that [HTTPDelete] I put on the controller. I am new to web development, so I'm sure there are other ways in javascript or jquery to do the same, but I'm just doing what I know at the moment.
source share