calling action method with javascript asp mvc

Sharp

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!");
        }
    });
}
Thilina Nakkawita

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: {
  },
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AJAX call in ASP.NET MVC application not calling Action method

From Dev

ASP.Net MVC keeps calling the index action method for each controller action method I call

From Dev

MVC traditional form action not calling controller method

From Dev

Calling a method in Razor ASP.NET MVC

From Dev

Calling a method in Razor ASP.NET MVC

From Dev

ASP.NET MVC calling a method

From Dev

ASP.NET MVC 5 calling controller method from Javascript Error

From Dev

MVC Calling ActionResult Method from JavaScript

From Dev

in Asp.net MVC Project calling an action through ajax not working

From Dev

MVC 4: Calling action method on dropdown list select change

From Dev

Asp.net MVC Ajax call not calling controller method

From Dev

Dropdown change not calling method asp.net mvc jquery

From Dev

Asp.net MVC 5 not calling controller create method

From Dev

Asp.net MVC Ajax call not calling controller method

From Dev

Is Delete Action Method without AntiForgeryToken unsafe in ASP.NET MVC?

From Dev

Take parameter of a method into custom action filter MVC3 asp

From Dev

Call an action method from layout in ASP.NET MVC

From Dev

asp.net mvc 5 asynchronous action method

From Dev

ASP.NET MVC RemoteAttribute does not trigger action method in controller

From Dev

ActionName Attribute & UrlHelper.Action Method in ASP.NET MVC

From Dev

Remove json field in ASP MVC WebApi Action Method

From Dev

Pass Comma Separated Value to ASP.NET MVC Action Method

From Dev

How to share same data one action method to other action method in ASP.NET MVC

From Dev

Calling method in MapRoute MVC

From Dev

Calling ASP.NET MVC 4 Controller from Javascript

From Dev

ASP.NET MVC calling server from javascript function with ajax

From Dev

Calling the controller correctly from JavaScript - ASP.NET MVC

From Dev

Transfering by calling Action method directly?

From Dev

Transfering by calling Action method directly?

Related Related

  1. 1

    AJAX call in ASP.NET MVC application not calling Action method

  2. 2

    ASP.Net MVC keeps calling the index action method for each controller action method I call

  3. 3

    MVC traditional form action not calling controller method

  4. 4

    Calling a method in Razor ASP.NET MVC

  5. 5

    Calling a method in Razor ASP.NET MVC

  6. 6

    ASP.NET MVC calling a method

  7. 7

    ASP.NET MVC 5 calling controller method from Javascript Error

  8. 8

    MVC Calling ActionResult Method from JavaScript

  9. 9

    in Asp.net MVC Project calling an action through ajax not working

  10. 10

    MVC 4: Calling action method on dropdown list select change

  11. 11

    Asp.net MVC Ajax call not calling controller method

  12. 12

    Dropdown change not calling method asp.net mvc jquery

  13. 13

    Asp.net MVC 5 not calling controller create method

  14. 14

    Asp.net MVC Ajax call not calling controller method

  15. 15

    Is Delete Action Method without AntiForgeryToken unsafe in ASP.NET MVC?

  16. 16

    Take parameter of a method into custom action filter MVC3 asp

  17. 17

    Call an action method from layout in ASP.NET MVC

  18. 18

    asp.net mvc 5 asynchronous action method

  19. 19

    ASP.NET MVC RemoteAttribute does not trigger action method in controller

  20. 20

    ActionName Attribute & UrlHelper.Action Method in ASP.NET MVC

  21. 21

    Remove json field in ASP MVC WebApi Action Method

  22. 22

    Pass Comma Separated Value to ASP.NET MVC Action Method

  23. 23

    How to share same data one action method to other action method in ASP.NET MVC

  24. 24

    Calling method in MapRoute MVC

  25. 25

    Calling ASP.NET MVC 4 Controller from Javascript

  26. 26

    ASP.NET MVC calling server from javascript function with ajax

  27. 27

    Calling the controller correctly from JavaScript - ASP.NET MVC

  28. 28

    Transfering by calling Action method directly?

  29. 29

    Transfering by calling Action method directly?

HotTag

Archive