我正在使用Datatable jQuery,我想在按钮内的每一行上调用删除操作...我如何重定向到具有正确参数的控制器用户的操作方法删除?
var datatableVariable = $('#myTable').DataTable({
....
columns: [
...column definition...{
data: null,
render: function(data, type, row) {
return "<a href='#' class='btn btn-danger' onclick=DeleteData('" + row.id + "'); >Delete</a>";
}
},
],
});
function DeleteData(id) {
if (confirm("Are you sure you want to delete ...?")) {
Delete(id);
} else {
return false;
}
}
function Delete(id) {
var url = '@Url.Content("~/")' + "Users/Delete";
$.post(url, {
ID: id
}, function(data) {
if (data) {
oTable = $('#myTable').DataTable();
oTable.draw();
} else {
alert("Something Went Wrong!");
}
});
}
答案 0 :(得分:1)
我假设您只想在控制器中调用操作方法。
使用Ajax
$.ajax({
type: "POST",
url: "/Users/Delete",
data: { ID: id},
success: {
},
});