Pass parameters to the controller via ajax

Asked

Viewed 2,036 times

0

Guys I don’t know anything about jquery/ajax and wanted to pass a parameter to the controller.

I have a modal that opens only to ask if the person is aware of the cancellation where the only field that it is necessary to pass is a Hidden with the id of which will be deleted.

would also like to know how to get my controller. I am using Asp net mvc 5.

<script>
    $(function () {              

        jQuery('button.delete').on('click', function () {
            var $row = jQuery(this).closest('tr');
            var $columns = $row.find('td');

            $("#nrotitulo").val($row.find('td:eq(1)').text());
            $("#razao").val($row.find('td:eq(2)').text());
            $("#cnpjtitulo").val($row.find('td:eq(3)').text());
            $("#valortitulo").val($row.find('td:eq(7)').text());
            $row.find('td:eq(8)').text()
            $row.find('td:eq(9)').text()

            var obj = {
            titulonro : $("#nrotitulo").val($row.find('td:eq(1)').text()),
            razaosocial : $("#razao").val($row.find('td:eq(2)').text()),
            titulocnpj : $("#cnpjtitulo").val($row.find('td:eq(3)').text()),
            titulovalor : $("#valortitulo").val($row.find('td:eq(7)').text()),
            systicketID : $row.find('td:eq(8)').text(),
            aditiveID : $row.find('td:eq(9)').text()
            };

            var parametros = JSON.stringify(obj);
                alert('error');
        });

        $("#btn-delete").click(function () {
            alert('ok');
            $.ajax({
                type: 'POST',
                url: '/Cliente/TicketDelete',
                contentType: "application/json; charset=utf-8",
                data: parametros,
                dataType: "json",
                success: function (parametros) {

                }
            });

    });
});

</script>

1 answer

1


Just pass the ID on the date:

data: { "id": id},

In your Controller:

[HttpPost]
public ActionResult GetID(int id){ }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.