How to send multiple parameters from kendo datasource read operation to WebApi controller

I have the following scenario, I have a kendo.dataSource that is populated via a read request to a WebApi controller. In addition to reading, I send several parameters which I then use in my controller to execute some server logic. I was able to send as many simple parameters as I want using the parameterMap property of the transport function. So far, this has been a simple pull request. However, now I need to send an additional json object to the controller as a parameter. I read that I need to convert the Get request to Post and put Json in the request body, but I don't know how.

The code I have so far:

var gridDataSource = new kendo.data.DataSource({
        type: 'odata-v4',
        transport: {
            read: {
                url: wave.alarmsAndEvents.api('api/alarmsAndEventsSearch/post'),
                type: "POST",
                data: {
                    SearchModel: JSON.stringify(vm.searchModel)
                },
                contentType: 'application/json; charset=utf-8',

            },

            parameterMap: function (data, operation) {
                if (operation === "read") {
                    data.startDate = kendo.toString(vm.selectedTimeInterval.start, "G");
                    data.endDate = kendo.toString(vm.selectedTimeInterval.end, "G");
                    data.alarmsToDisplay = vm.maxRecords;
                }
                return kendo.stringify(data);
            }
        },
        pageSize: vm.maxRecords,
        error: function (e) {
            alert(e.xhr.responseText);
        }
    });

      

SearchModel

is what I want to send as JSon

. The rest are simple parameters DateTime

and int

.

My controller:

[HttpPost]
    public IQueryable<AlarmsSearchViewModel> Post(DateTime startDate, DateTime endDate, int alarmsToDisplay, [FromBody]JToken jsonbody)
    {
        ....
        return something;
    }

      

It works out in the end Not Found 404

, but I'm pretty sure I messed up the parameters. And from the Network window I can see that the json object is not being sent at all. Any help would be much appreciated!

+3


source to share





All Articles