0

I work in Durandal project and enjoy using kendo-ui grid (of Telerik company).

I use create feature also. It sasy that in grid declaretion I have the following code:

  transport: {                        
                    create: {
                        url: myUrl,
                        type: 'POST',
                        dataType: 'json'
                    }
             },

My grid is dinamic. It says that grid schema and columns are built on run-time. So, the server method need to accept the data by generic object, for example: dataTable. I cannot accept specific type, like: Product/ Pupils/ Car.

What is the correct way to implement my server-side? What does the contoller method have to accept?

Dimitri Dewaele
  • 10,311
  • 21
  • 80
  • 127
user5260143
  • 1,048
  • 2
  • 12
  • 36

1 Answers1

0

I've never tried it, but you should be able to pass a JSON.net JObject in and out of your controller, something like:

[HttpPost]
public JObject PostAlbumJObject(JObject jobj)
{
    // dynamic input from inbound JSON
    dynamic data = jobj;

    data.someProperty;

    return jobj;
}

However on the Kendo side, I'm not sure if the DataSource will send create requests to the server unless there is an id specified, using schema.model.id

var ds = new kendo.data.DataSource({
    schema: {
        model: {
             id: "someIdField"
        }
    }
});

Internally, Kendo checks to see if the field set as the ID is set to the default value (undefined or 0) and if it is, it assumes the object is new. When you return the object again from the server, it MUST have the ID field set to a value, otherwise Kendo will keep sending the item to the server thinking it is still new (because it does not have an ID).

CodingWithSpike
  • 42,906
  • 18
  • 101
  • 138