Issues sending selected rows values into a controller

3 posts, 0 answers
  1. Juan
    Juan avatar
    24 posts
    Member since:
    Oct 2016

    Posted 14 Nov 2016 Link to this post

    Please i need someone can help me with this problem.

    I'm trying to send the selected rows into a controller when i click on the button with id="send", the issue is that when i tried to send other values( in this case a number and a string) with the selected rows values, the selected rows values is sending null to the controller but the number and the string isn't null in the controller parameters.

    This is my javascript code that works fine if only i send the selected rows values:

    $('#send').click(function () {
                    var items = {};
                    var grid = $('#grid').data('kendoGrid');
                    var selectedElements = grid.select();

                    for (var j = 0; j < selectedElements.length; j++) {
                        var item = grid.dataItem(selectedElements[j]);
                        items['grid[' + j + '].ParecidoCodigo'] = item.ParecidoCodigo;

                    }
                    $.ajax({
                        url: '@Url.Action("Index", "Busqueda")',
                        type: "POST",
                        async: false,
                        data: items,

                        success: function (result) {
                            console.log(result);
                        }
                    })
                })

    and this is my controller method action:

    public ActionResult Index(MarcaParecido[] grid)
    {

        ...

    }

    Everything works fine until now.

    BUt when i tried to send another values like this:

    $('#send').click(function () {
                    var items = {};
                    var grid = $('#grid').data('kendoGrid');
                    var selectedElements = grid.select();
                    var enviarDest = $('#destinatario').val();
                    var marca = $('#numMarca').val();

                    for (var j = 0; j < selectedElements.length; j++) {
                        var item = grid.dataItem(selectedElements[j]);
                        items['grid[' + j + '].ParecidoCodigo'] = item.ParecidoCodigo;

                    }
                    $.ajax({
                        url: '@Url.Action("Index", "Busqueda")',
                        type: "POST",
                        async: false,
                        data: { items, marcas: marca, destinatario: enviarDest },

                        success: function (result) {
                            console.log(result);
                        }
                    })
                })

     

    The selected rows values is sending me null, but hte others values isn't null

    This is my controller now:

    public ActionResult Index(MarcaParecido[] grid, string marcas, string destinatario)
            {...}

     

    Please i really need your help with this, i don't know what else can i do to send all the values when i click the button.

    I tried with JSON.stringify too but it doesn't work :(

     

    I'll wait for your answers. Big hugs.

     

  2. Daniel
    Admin
    Daniel avatar
    2231 posts

    Posted 16 Nov 2016 Link to this post

    Hello Juan,

    You should add the additional values to the items object and use items for the request data in order to bind the values e.g.
    var items = {
        marcas: $('#numMarca').val(),   
        destinatario: $('#destinatario').val()
    };
    ...
    $.ajax({
        url: '@Url.Action("Index", "Busqueda")',
        type: "POST",
        async: false,
        data: items,



    Regards,
    Daniel
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Juan
    Juan avatar
    24 posts
    Member since:
    Oct 2016

    Posted 21 Nov 2016 in reply to Daniel Link to this post

    Thanks that help me a lot.
Back to Top