我試圖用批量刪除來創建網格,並且我在後端(asp.NET WebApi)上遇到了問題。從kendo數據源發送到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.請求到服務器的樣子(從鉻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
確實沒有看到你的MessageHeader類有點難,但假設你的動作需要一個'IEnumerable頭文件''我希望你的JavaScript對象是一個數組。 –
2014-09-11 11:53:33
@BenRobinson增加了額外的信息。 – jajdoo 2014-09-11 11:58:58