简体   繁体   English

Kendo Scheduler-读取数据源-将字符串数组发布到Web API

[英]Kendo Scheduler - Read datasource - Post array of strings to Web API

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. 我正在尝试完成以下操作,通过POST请求获取用户的约会,因为我需要发布其他日历ID来获取其他用户的约会。 The POST request is sent to a Web API. POST请求发送到Web API。 The endpoint gets hit but the array of calendarIds is always empty. 端点被命中,但是calendarIds数组始终为空。

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: 这是Web API的实现:

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

// calendarIds is always empty

This the request posted content (textView) from fiddler: 这是请求提琴手发布的内容(textView):

{"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: 整个Raw请求:

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"]}

You may try annotating your WebAPI post method with [FromBody] attribute 您可以尝试使用[FromBody]属性注释WebAPI post方法

    [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 您现在发送的内容{“ calendarIds”:[“ 1c78e75f-9516-42cf-a439-271ee997abf1”]}是一个对象,而WebAPI方法接受一个数组

You can try: 你可以试试:

    parameterMap: function(data, type) {
                      if (type === "read") {
                          var values = data.calendarIds.split(','),
                          return JSON.stringify(values);
                      }
                  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM