0

Using le framework here

http://blog.longle.net/2014/03/04/harness-the-power-of-asp-net-mvc-web-api-odata-kendo-ui-requirejs-to-build-an-easy-maintainable-spa-for-the-net-developer-published/

and here

Web API + OData - PATCH request 400 error

how to send key delta in patch update of WebAPI 2 odata where kendo datasource "batch: true"

AcceptVerbs("PATCH", "MERGE")]
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<Company> patch)

The key is always empty!!!

Does WebAPI odata supported by kendo?

4

1 回答 1

0

Since it is a very specific task, I have only one tweak that is working for Repository Pattern provided by Le framework shown in the above mentioned link.

define(['kendo', 'testModel'],
function (kendo, testModel) {
    var svcUrl = '/odata/modelURL';
    var ds_test = new kendo.data.DataSource({
        type: 'odata',
        transport: {
            read: {
                //async: false,
                url: svcUrl,
                dataType: 'json'
            },
            update: {
                url: function (data) {
                    return svcUrl + '(' + data.models[0].ID + ')';
                },
                dataType: 'json',
                type: 'PATCH'
            },
            create: {
                url: function (data) {
                    return svcUrl + '(' + data.models[0].ID + ')';
                },
                dataType: 'json',
                type: 'PATCH'
            },
            destroy: {
                url: function (data) {
                    return svcUrl + '(' + data.models[0].ID + ')';
                },
                dataType: 'json',
                type: 'PATCH'
            },
            parameterMap: function(data, operation) {
                if (operation != 'read') {
                    var model = kendo.stringify(data.models[0]);
                    return model;
                };
                return data.models;
            }
        },
        batch: true,
        serverPaging: true,
        serverSorting: true,
        serverFiltering: true,
        pageSize: 10,
        schema: {
            data: function (data) { return data['value']; }, //{ return data.value; },
            total: function (data) { return data['odata.count']; },
            model: testModel
            //parse: function(response) {
            //    var f = ds_appl_home.options.schema.model.fields;
            //    $.each(response, function (key, value) {
            //        if (!(key.toString() in f)) {
            //            delete response[key];
            //        }
            //    });
            //    return response;
            //}
        },
        error: function (e) {
            ...
        }
    });
    return ds_test;
});
于 2014-06-24T09:02:17.047 回答