Frage

I am trying to accomplish following, get appointments of a user through POST request as I need to post other calendar ids to get appointments of other users as well. The POST request is sent to a Web API. The endpoint gets hit but the array of calendarIds is always empty.

This is the datasource definition:

dataSource: new kendo.data.SchedulerDataSource({
                batch: true,
                transport: {
                    read: {
                        url: "/api/MyCalendar/GetAppointments",
                        dataType: "json",
                        type: "POST"
                    },
                    parameterMap: function(data, type) {
                        if (type === "read") {
                            return JSON.stringify(data);
                        }
                    }
                }

This is the Web API implementation:

[HttpPost]
        public HttpResponseMessage GetAppointments(string[] calendarIds)
        {

// calendarIds is always empty

This the request posted content (textView) from fiddler:

{"calendarIds":["1c78e75f-9516-42cf-a439-271ee997abf1"]}

I am not sure what is wrong in here, thanks for any help on this.

Update:

The whole Raw request:

POST http://xxxxx/api/MyCalendar/GetAppointments HTTP/1.1
Host: ccmspatientmanager
Connection: keep-alive
Content-Length: 56
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://xxxxx
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://xxxxx/Home/MyCalendar
Accept-Encoding: gzip,deflate,sdch
Accept-Language: cs,en-GB;q=0.8,en;q=0.6,de-DE;q=0.4,de;q=0.2,sk;q=0.2
Cookie: ASP.NET_SessionId=flcab5ecct1zaopgqmpz0rhg; .ASPXAUTH=DAED17623F4B0E8F4AB0C3176EC0B73DD29A65650E93DB9664D52C9D23D34C52F1B312923B0A5F8A0D66DAF5C72864BF5827CC667D181DDE5EBC43C651D3C41FBFF315884DD74272E74E4A08D0D2380696B1C5B6

{"calendarIds":["1c78e75f-9516-42cf-a439-271ee997abf1"]}
War es hilfreich?

Lösung

You may try annotating your WebAPI post method with [FromBody] attribute

    [HttpPost]
    public HttpResponseMessage GetAppointments([FromBody]string[] calendarIds)

Also make sure you are passing in an Array in the request body instead of an Object. What you are sending right now {"calendarIds":["1c78e75f-9516-42cf-a439-271ee997abf1"]} is an object whereas the WebAPI method accepts an Array

You can try:

    parameterMap: function(data, type) {
                      if (type === "read") {
                          var values = data.calendarIds.split(','),
                          return JSON.stringify(values);
                      }
                  }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top