This is a migrated thread and some comments may be shown as answers.

Issues sending selected rows values into a controller

2 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Juan
Top achievements
Rank 1
Juan asked on 14 Nov 2016, 01:32 PM

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 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 16 Nov 2016, 08:18 AM
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.
0
Juan
Top achievements
Rank 1
answered on 21 Nov 2016, 03:48 PM
Thanks that help me a lot.
Tags
Grid
Asked by
Juan
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Juan
Top achievements
Rank 1
Share this question
or