undefined id

undefined id

MpicholMpichol Posts: 2Questions: 1Answers: 0
edited June 2017 in Free community support

hi that is part of the code for may datatable

dt = $('#nomes-data-table').DataTable({
                            "serverSide": true,
                            "processing": true,
                            "ajax": {
                                "url":
                                "@Url.Action("Get", "Nomes")",
                                "data": function (data) {
                                    data.id = $("#id").val();
                                }
                            },
                            "columns": [
                              
                                {
                                    "title": "Nome",
                                    "data": "NomeRazaoSocial",
                                    "searchable": true
                                },
                               {
                                   "title": "Tipo",
                                   "data": "TipoNome",
                                   "searchable": true
                               },
                                 .....
                                {
                                    "title": "Actions",
                                    "data": "id",
                                    "searchable": false,
                                    "sortable": false,
                                    "render": function (data, type, full, meta) {
                                        return '<a href="@Url.Action("Edit", "Nomes")?id=' + data + '" class="editNome">Edit</a>';
                                    }
                                }
and that is action
$('#nomes-data-table').on("click", ".editNome", function (event) {
                    event.preventDefault();
                    var url = $(this).attr("href");
                    $.get(url, function (data) {

                        $('#editContainer').html(data);
                        $('#editModal').modal('show');
                    });
                });

The problem is that var url does not return the id of the row.

Thanks

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    The id of what row? You've got ajax.data sending the value of the #id element. I'm not actually clear on what you are trying to achieve here.

    Allan

  • MpicholMpichol Posts: 2Questions: 1Answers: 0

    Hi Allan
    That is exactly what i am doing

    Line 7
    I get the value of the id
    "data": function (data) { data.id = $("#id").val(); }

    Line 29
    It is the action to edit the row
    "render": function (data, type, full, meta) {
                                            return '<a href="@Url.Action("Edit", "Nomes")?id=' + data + '" class="editNome">Edit</a>';
                                        }

    But then on the script function line 34 i get id undefined!

    If you could help me a would appreciate
    Thank you
    Michel Pszczol

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    I still don't get it - sorry. Can you link to a page showing the issue please?

    The code above suggests that the response from the server should contain an id property for the object that describes each row. Are you saying it doesn't? A test case really would be useful.

    Thanks,
    Allan

This discussion has been closed.