0

I'm trying to create a grid with batch delete, and I am having trouble on my back-end (asp.NET WebApi).

I have set up the following data source:

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

and the relevant parts of the api controller:

    // 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);
    }

The request reaches deleteMessages, but the headers appears to be empty

I'm guessing it set it up wrong, but I cant figure out whats wrong..

edit: 1. the MessageHeader class (imported from a wcf service if wonder about the attributes):

[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. the request to the server looks like (from 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
jajdoo
  • 516
  • 1
  • 9
  • 21
  • It's a bit hard to be sure without seeing your MessageHeader class, but given that your action takes an `IEnumerable headers)` I would expect your JavaScript object to be an array. – Ben Robinson Sep 11 '14 at 11:53
  • @BenRobinson added additional information. – jajdoo Sep 11 '14 at 11:58

2 Answers2

0

I had the exact same problem. remove batch: true

Christoph Adamakis
  • 865
  • 2
  • 9
  • 26
0

For me this sounds like the problem with a body in a HTTP DELETE request. (see Is an entity body allowed for an HTTP DELETE request?)

If a DELETE request includes an entity body, the body is ignored [...]

PS: Can you try with a public constructor without parameters in the MessageHeader class?

Community
  • 1
  • 1
niklr
  • 1,671
  • 3
  • 24
  • 40