I have a datatable that gets values from a database with on every line on the last column a delete button.
$"<button type='submit' class='btn btn-danger test' id='{i.id}' onclick='return Delete();'>Delete</button>"
My button gets an id which is the id of the model from that row.
I want to delete the row if I click on the button. But can't figure out how to call the method without my application trying to find the view. (I have no delete view and don't want to make one). I've looked it up but nothing works.
My controller action :
[Authorize(Roles = "user")]
[HttpDelete]
public ActionResult Delete(Guid id)
{
if (BLayer.getAllGames().ToList().Exists(x => x.id == id))
{
BLayer.DeleteGame(id);
}
return new EmptyResult();
}
My Jquery function :
function Delete() {
var table = $("#tableOverviewGames").DataTable();
$('#tableOverviewGames tbody').on('click', 'button', function () {
var idGame = $(this).attr('id');
$.ajax({
url: "Delete",
type: 'DELETE',
data: { id: idGame },
async: false,
contentType: false,
success: function (data) {
alert("Vous avez supprimé le jeu");
},
error: function (data) {
console.log(data);
}
});
});
}
Can someone help me please?
Thanks!
EDIT:
This is the error I get in the console :
DELETE http://localhost:3673/Game/Delete 404 (Not Found)