Update in kendo grid in mobile app does not send model

249 views Asked by At

I am trying to update a row from a grid in a mobile app , but the model is not sent to the server.

I am using kendo 2015.1.429

My view is this:

<div data-role="view" data-init="initGrid" data-stretch="true">
    <div data-role="header">
    </div>
    <div id="grid">
    </div>
</div>
    <script type="text/javascript">
    function initGrid() {

        var dataSource3 = new kendo.data.DataSource({
            transport: {
                read: {
                    url:  "@Url.Action("GetAll")",
                    dataType: "json"
                },
                update: {
                    url: "@Url.Action("Update")",
                    dataType: "json"
                },
                destroy: {
                    url: "@Url.Action("Destroy")",
                    dataType: "json"
                },
                create: {
                    url: "@Url.Action("Create")",
                    dataType: "json"
                },
                parameterMap: function (options, operation) {
                    if (operation !== "read" && options.models) {
                        return { models: kendo.stringify(options.models) };
                    }
                }
            },
            batch: false,
            schema: {
                data:"Data",
                model: {
                    id: "ID",
                    fields: {
                        ID: { type: "number", editable: false, nullable: false },
                        Name: { type: "string" }

                    }
                }
            }
        });

        $("#grid").kendoGrid({
            dataSource:dataSource3,
            pageable: true,
            mobile: "tablet",
            height: kendo.support.mobileOS.wp ? "24em" : 430,
            resizable: true,
            editable: {
                mode: "popup"

            },
            toolbar: ["create"],
             columns: [
                        { field: "ID", title: "ID", width: 200},
                        { field: "Name", title: "Name"},       
                        { command: ["edit", "destroy"] } 
                      ]
        });
  }
</script>

The Update method in controller is this:

 public ActionResult Update([DataSourceRequest] DataSourceRequest request, Model viewModel)
        {

            return Json(new[] { viewModel }.ToDataSourceResult(request, ModelState));

        }

<--EDITED 2 --> I saw in Fiddler that no data is sent to my method Update.

What am I forgetting to do? What am I doing wrong?

1

There are 1 answers

0
Gringo On

If I remove parameterMap

  parameterMap: function (options, operation) {
                    if (operation !== "read" && options.models) {
                        return { models: kendo.stringify(options.models) };
                    }
                }

It works fantastic.

Thanks!