0

我正在尝试使用批量删除创建一个网格,但我的后端(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
4

2 回答 2

0

对我来说,这听起来像是 HTTP DELETE 请求中的正文问题。(请参阅HTTP DELETE 请求是否允许实体主体?

如果 DELETE 请求包含实体主体,则该主体将被忽略 [...]

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

于 2014-11-07T13:13:25.527 回答
0

我有同样的问题。删除批次:真

于 2014-11-07T12:51:08.057 回答