用javascript asp mvc调用动作方法

时间:2018-08-07 08:40:04

标签: javascript asp.net-mvc datatables

我正在使用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!");
        }
    });
}

1 个答案:

答案 0 :(得分:1)

我假设您只想在控制器中调用操作方法。

使用Ajax

$.ajax({
  type: "POST",
  url: "/Users/Delete",
  data: { ID: id},
  success: {
  },
});