0

i am trying to send model data from a form to the controller through kendo ui grid. I have yet to find any help on this.

  1. Can i just serilize the form data and send it as a paramater?

Here is my grid code,

enter@(Html.Kendo().Grid<LookupGridResults>()
                                .Name("grid")

                                .Columns(columns =>
                                {
                                    columns.Bound(p => p.FirstName).Width(225);
                                    columns.Bound(p => p.LastName).Width(225);
                                    columns.Bound(p => p.City).Width(225);
                                    columns.Bound(p => p.County).Width(225);
                                    columns.Bound(p => p.State).Width(225);
                                    columns.Bound(p => p.Zip).Width(225);
                                })
                                .Pageable()
                                .Sortable()
                                .Scrollable()
                                .HtmlAttributes(new { style = "height:550px;" })
                                .DataSource(dataSource => dataSource
                                    .Ajax()
                                    .PageSize(50)
                                    .ServerOperation(true)
                                    .Read(read => read.Action("ReadLeads", "LeadsManagement"))

                                 )

                                    ) 

I want to try to do this as an ajx call to the controller if possible.

jeffkenn
  • 201
  • 4
  • 16

1 Answers1

1

You can use grid.dataSource.read method with data object parameter (http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-read):

var optionalData = { foo: 42, bar: "baz" };
dataSource.read(optionalData);

Or if you want custom action request, then there is undocumented dataSource.success method:

$.ajax({
    type: "POST",
    url: '...',
    data: {....},
    success: function (data) {
        //data is array of grid items to rebind
        grid.dataSource.success(data);
    }
});

Update

To collect data from form i am using jquery extension serializeObject (https://stackoverflow.com/a/1186309/5575536):

$.fn.serializeObject = function()
{
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

And usage is next:

var data = $('#form').serializeObject();
//or
var data = $('#container').find('input,select,textarea').serializeObject();
Community
  • 1
  • 1
Gene R
  • 3,684
  • 2
  • 17
  • 27
  • but if i have, lets day, 25 controls that have data to be sent to the controller, ho can i just send the serialised form data? – jeffkenn Feb 29 '16 at 21:44