0

i am using Datatable jquery and i would like to call delete action on every row inside a button ...how can i redirect to action method delete of the controllers User with the right parameter?

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 Answer 1

1

I assume you just want to call your action method in the controller.

Use Ajax

$.ajax({
  type: "POST",
  url: "/Users/Delete",
  data: { ID: id},
  success: {
  },
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.