从kendo数据源发送到web api参数的绑定集合失败

时间:2014-09-11 11:46:49

标签: c# asp.net-web-api kendo-ui kendo-grid kendo-datasource

我正在尝试使用批量删除创建一个网格,我的后端遇到了麻烦(asp.NET WebApi)。

我已设置以下数据源:

    var QueueMessages = {
    transport: {
        read: {
           // omitted
        },
        destroy: {
            url: "api/QueueMessages/deleteMessages",
            dataType: "json",
            type: "DELETE"
        }
    },
    schema: {
        // omitted
    },
    autoSync: false,
    batch: true
};

以及api控制器的相关部分:

    // batch version
    [HttpDelete]
    public HttpResponseMessage deleteMessages(IEnumerable<MessageHeader> headers)
    {
        foreach( MessageHeader header in headers )
        {
            try
            {
                // delete each...
            }
            catch (Exception e)
            {
                // handle exceptions...
            }
        }
        return new HttpResponseMessage(HttpStatusCode.OK);
    }

请求到达deleteMessages,但headers似乎为空

我猜它设置错了,但我无法弄清楚什么是错的......

编辑: 1. MessageHeader类(如果想知道属性,从wcf服务导入):

[DataContract]
public class MessageHeader
{
    public MessageHeader(string id, string profileName, MessageQueueType queueType, DateTime acceptedAt, DateTime processedAt)
    {
        this.Id = id;
        this.ProfileName = profileName;
        this.QueueType = queueType;
        this.AcceptedAt = acceptedAt;
        this.ProcessedAt = processedAt;
    }

    [DataMember(Name="Id")]
    public String Id { get; private set; }

    [DataMember(Name="ProfileName")]
    public String ProfileName { get; private set; }

    [DataMember(Name = "QueueType")]
    public MessageQueueType QueueType { get; private set; }

    [DataMember(Name="AcceptedAt")]
    public DateTime AcceptedAt { get; private set; }

    [DataMember(Name="ProcessedAt")]
    public DateTime ProcessedAt { get; private set; }
}

2。对服务器的请求看起来像(来自chrome devtools):

models[0][AcceptedAt]:Thu Sep 04 2014 17:48:44 GMT+0300 (Jerusalem Daylight Time)
models[0][Id]:3c42c940-6711-4107-b02f-0e6842e1f771\424231
models[0][ProcessedAt]:Mon Jan 01 1 00:00:00 GMT+0200 (Jerusalem Standard Time)
models[0][ProfileName]:V11_DEV
models[0][QueueType]:0

2 个答案:

答案 0 :(得分:0)

我遇到了完全相同的问题。删除批次:true

答案 1 :(得分:0)

对我来说,这听起来像HTTP DELETE请求中的正文问题。 (见Is an entity body allowed for an HTTP DELETE request?

  

如果DELETE请求包含实体主体,则会忽略正文[...]

PS:您可以尝试使用MessageHeader类中没有参数的公共构造函数吗?