How to use Transport CRUD operation without specific model on the server side?

2 posts, 1 answers
  1. Dan
    Dan avatar
    5 posts
    Member since:
    Dec 2015

    Posted 13 Dec 2015 Link to this post

    I've been trying to get Keno Grid working in my app for a week now and I *finally* got to the point where the dataSource transport actually calls the controller action.  However, I cannot seem to get anything moving forward from there.

    I see have two problems right now.

    1) All the controller action examples I've seen so far seem to expect the incoming data to have a related model on the server side. For example:


    public JsonResult Update()
       var employees = this.DeserializeObject<IEnumerable<EmployeeDirectoryModel>>("models");
       if (employees != null)
          foreach (var employee in employees)
       return this.Jsonp(employees);

    However, I do not have something similar to EmployeeDirectoryModel (in the above example) to which I can deserialize the incoming data.  The data being submitted from the client needs to be ultimately just be json which I will store in a completely unrelated model as a string.


    public class ClientRow
        public Guid Id { get; set; }
        public Guid TableId { get; set; }
        public string RowData { get; set; }  // json here


    2) When trying to figure out a workaround for the above I was having troubles figuring out where (and in what form) the data being sent from the client is.  I put a break point in the controller action and looked around in the context and could not find ANY data that would have been sent.  So then I opened Fiddler and could not find the data anywhere in the request packet for the Update.

    I'm assuming I have something misconfigured somewhere.  Here is my entire function which draws the grid.  What here is not configured properly so that the Update event would be triggered but no data would go over the wire?


    var gridName = '#' +controlId + '-grid';
    var dataSource = new{
        transport: {
            read: {
                url: '/Data/Read/' + componentId,
                dataType: 'json'
            update: {
                url: '/Data/Update',
                dataType: 'json'
            destroy: {
                url: '/Data/Destroy',
                dataType: 'json'
            create: {
                url: '/Data/Create',
                dataType: 'json'
            parameterMap: function (options, operation) {
                if (operation !== "read" && options.models) {
                    return { models: kendo.stringify(options.models) };
        pageSize: 20,
        schema: {
            model: {
                id: "Id",
                fields: {
                    "Id": { "editable": false, "nullable": false },
                    "Category": { "validation": { "required": true } },
                    "Product": { "validation": { "required": true } },
                    "Color": { "validation": { "required": true } },
                    "Cost": { "type": "number", "validation": { "required": true } },
                    "MSRP": { "type": "number", "validation": { "required": true } }
    var grid = $(gridName).kendoGrid({
        dataSource: dataSource,
        selectable: true,
        groupable: true,
        sortable: true,
        editable: "inline",
        toolbar: ["create", "save", "cancel"],
        columns: [
            { field: "User", title: "User" },
            { field: "Category", title: "Category" },
            { field: "Product", title: "Name" },
            { field: "Color", title: "Color" },
            { field: "Cost", title: "Cost", format: "{0:c}" },
            { field: "MSRP", title: "MSRP", format: "{0:c}" },
            { field: "EditedOn", title: "Edited On" },
            { command: ["edit", "destroy"] , title: " " }

    Please note: in the example code above I clearly have a defined model, but this is just sample code.  The model/columns are all derived dynamically from some other data and the json for the dataSource "fields" and the grid "columns" are generated on the fly. There is no way to know what the actual model will look like and therefore I cannot have a defined model to deserialize on the server side.






  2. Answer
    Rosen avatar
    3247 posts

    Posted 16 Dec 2015 Link to this post

    Hello Dan,


    You could store the model to a string if this is what you are looking for. In the snippet you have pasted (which I guess is taken from our demo's sample service) the changes are send as a JSON string in the models request param. Thus, it is a string, which then is deserialized into a the concrete typed instances.


    Regarding the other issue you have described. There is no data send to the server due to incorrect parameterMap implementation. The parameterMap you have pasted requires DataSource to be set in batch mode, which is not true in the pasted code. The requirement comes from the use of the condition which expects a models to be present. This is only true when using batch editing as method in the docs here.


    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top