Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Following is my grid.
C#
@(Html.Kendo().Grid<VehicleUploadViewModel>()
                        .Name("grid")
                        .Resizable(resize => resize.Columns(true))
                        .Columns(columns =>
                              {
                                  columns.Bound(p => p.ID).Visible(false);
                                  columns.Bound(p => p.RefId).Width(15);
                                  columns.Bound(p => p.IsAcceptReturn).Width(15).ClientTemplate("<input type='checkbox' #= IsAcceptReturn ? 'checked=checked' : '' #></input>");
                                  columns.Bound(p => p.ReturnDuration).Width(15);
                                  columns.Bound(p => p.CurrentSellingMethodId).Width(15);
                                  columns.Bound(p => p.SuggestedOfferPrice).Width(15);
                                  columns.Bound(p => p.Summary).Width(15);
                              })
                                        .ToolBar(toolbar =>
                                    {
                                        toolbar.Save();
                                    })
                                .Pageable(p => p.Refresh(true))
                                .Sortable()
                                .Editable(editable => editable.Mode(GridEditMode.InCell)) // Use in-cell editing mode
                                .Scrollable(scrollable => scrollable
                                .Height(366))
                                .Filterable()
                                .Groupable()
                                .Navigatable()
                                .HtmlAttributes(new { style = "width:1138px;" })
                                .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
                                .Reorderable(reorder => reorder.Columns(true))
                                .DataSource(dataSource => dataSource
                                    .Ajax()
                                    .Batch(true)
                                    .PageSize(10)
                                    .ServerOperation(false)
                                    .Events(events => events

                                        .Error("error_handler")
                                        .RequestEnd("onRequestEnd"))

                                        .Model(model =>
                                            {
                                                model.Id(p => p.ID);
                                            })
                                            .Read(read => read.Action("UploadRead", "Upload"))
                                            .Update(update => update.Action("Editing_Update", "Upload")))
                                            .Events(e => e.DataBound("onDataBound").Cancel("onCancel"))
                        )


In my script tag, following is the code. I am assigning a blank source to the kendo grid on document ready.

JavaScript
<script>
    var grid;
    $(document).ready(function () {
        grid = $("#grid").data("kendoGrid");
        grid.dataSource.data([]);
    });
    function onUploadSuccess(e) {
    {
        grid.dataSource.data(e.response.Data);
    }
</script>


Following is the code from my action result which gives new data source to grid in onUploadSuccess function.

C#
var request = new DataSourceRequest();
return this.Json(lstUploadVehicles.ToDataSourceResult(request));


C#
Now, the new data is bounded in the grid, I am able to edit the records. But SaveChange is not called.

Here is my save method


C#
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Editing_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<VehicleUploadViewModel> vehicleUpload)
{
}


Why I am not able to call save changes method?
Posted

1 solution

C#
.Model(model =>{model.Id(p => p.ID);})


There was issue with ID field, all the ID were set to 0.
So need to have unique values for the field which you are binding.

Solved
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900