kendo datasource在使用ajax時默認使用GET,但可以通過定義傳輸設置來使用POST來使用POST。
以下是使用帖子在Telerik kendo CRUD example處縮短的代碼版本。
<script>
$(function() {
$("#grid").kendoGrid({
toolbar: ["create", "save", "cancel"],
dataSource: {
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
UnitPrice: { type: "number", validation: { required: true } }
}
}
},
transport: {
create: {
url: "Products.svc/Create",
contentType: "application/json; charset=utf-8",
type: "POST"
},
read: {
url: "Products.svc/Read",
contentType: "application/json; charset=utf-8",
type: "POST"
},
parameterMap: function(data, operation) {
if (operation != "read") {
return JSON.stringify({ products: data.models })
}
}
}
}
});
});
</script>
我已經包含了kendo.aspnetmvc。 min.js.當我用[HttpPost]裝飾我的動作時,網格不再更新。只有Action是[HttpGet]時纔會更新。你能告訴我他們在談論這個文檔的位置嗎?在我提供的鏈接中,他們說它會執行HttpGet請求。 HttpPost從未被提及。 – user1304444 2012-07-18 15:29:21
找到了。你完全正確。我的腳本源中有拼寫錯誤。謝謝! – user1304444 2012-07-18 16:01:06
感謝此信息... – 2012-10-16 05:49:39