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

Kendo Grid: Save grid data on Button click...

3 Answers 1702 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Surabhi
Top achievements
Rank 1
Surabhi asked on 08 Sep 2012, 04:42 AM
I have a kendo grid that let's user add the rows manully. Once users are done adding rows, There is a button that uses Ajax post to post data to controller action.

How can I pass the data from grid as Enumerable of model to the action

 @(Html.Kendo().Grid(Of PEERS.ECFPropertyModel).Name("ECFProperty").      Columns(Sub(cols)                      cols.Bound(Function(it) it.PropertyID).ClientTemplate("<input type='checkbox' onClick='gridECFProperty_selectOnClick(this);' id='SelectProperty' value='#=PropertyID#'>#=PropertyID#</input>")                      cols.Bound(Function(it) it.PropertyName)                      cols.Bound(Function(it) it.CostSaving)                      cols.Bound(Function(it) it.ImplementationCost)                      cols.Bound(Function(it) it.TargetCompletionDate)                      cols.Bound(Function(it) it.ActualCompletionDate)                                End Sub ).Pageable().Scrollable().Sortable().Selectable().DataSource(Sub(d) d.Ajax().ServerOperation(True).Batch(True).                                                     Model(Sub(m) m.Id(Function(p) p.PropertyID)).PageSize(10).                                                     Read(Function(r) r.Action("ECFPropertyList""ECFProperty", Request.RequestContext.RouteData.Values)).                                                     Update(Function(u) u.Action("SaveECFProperty1""ECFProperty", Request.RequestContext.RouteData.Values))       ))

<div> <input type="submit" id="submit" onclick="SaveECF();"  value="Save ECF Property" /> </div>


function SaveECF() {                           $.ajax({          url: '@Url.Action("SaveECFProperty""ECFProperty", Request.RequestContext.RouteData.Values)',          type: 'POST',          traditional: true,          datatype: "json",           data: {               PropertyList: $("#ECFProperty").data("kendoGrid").dataSource.view().toJSON),             currency:'USD'          },          success: function () { window.alert('saved'); }         });  }

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 12 Sep 2012, 02:12 PM
Hello Surabhi,

There are two approaches which I can suggest to send the data:
  • Use JSON in which case you should specify the contentType and convert the data to JSON. The observable array toJSON method just returns an JavaScript array with the data but you can use the kendo.stringify or JSON.stringify methods to convert the data e.g.
    function SaveECF() {
        $.ajax({
            url: '@Url.Action("SaveECFProperty", "ECFProperty", Request.RequestContext.RouteData.Values)',
            type: 'POST',
            traditional: true,
            dataType: "json",
            contentType: "application/json",
            data: kendo.stringify({
                propertyList:  PropertyList: $("#ECFProperty").data("kendoGrid").dataSource.view().toJSON(),
                currency: 'USD'
            }),
            success: function () { window.alert('saved'); }
        });
    }
  • Use form data which is default type. In this case you should convert the data into an object with properties in the format "ActionParameterName[i].PropertyName" equals value in order for the model binder to correctly bind the collection.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gaurav
Top achievements
Rank 1
answered on 22 Nov 2012, 06:58 AM
hi Daniel

i am not able to understand these lines can u eloberate them with some example


"Use form data which is default type. In this case you should convert the data into an object with properties in the format "ActionParameterName[i].PropertyName" equals value in order for the model binder to correctly bind the collection."

 

i am not able to Deserialize my data
Request.Form[0] gives me the result shown in picture


dynamic

 

 

dynObj = (List<MyViewModel>)serializer.Deserialize(Request.Form[0], typeof(List<ViewModel>));

please help me to bind data to my object

 


0
Navin
Top achievements
Rank 1
answered on 06 Nov 2013, 07:32 PM
Can you please provide an example of using the second approach?

Thanks
Tags
Grid
Asked by
Surabhi
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Gaurav
Top achievements
Rank 1
Navin
Top achievements
Rank 1
Share this question
or