0
我在页面中定义一个网格:KendoUI网更新问题
<div id="grid"></div>
<script>
$(document).ready(function() {
var crudServiceBaseUrl = "http://demos.kendoui.com/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "/Grid/GetPerson",
dataType: "json",
contentType: 'application/json; charset=utf-8',
type: 'Get'
},
update: {
url: function (person) {
debugger;
return "/Grid/Update";
},
contentType: 'application/json; charset=utf-8',
type: "POST",
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "ID",
fields: {
ID: { type: "number", editable: false, nullable: true },
Name: { validation: { required: true } },
Family: { validation: { required: true, min: 1 } },
Tel: {}
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 430,
toolbar: ["create"],
columns: [
{ field: "Name", title: "نام" },
{ field: "Family", title: "فامیل" },
{ field: "Tel", title: "تلفن", width: "100px" },
{ command: [{ name: "edit", text: "ویرایش" }, { name: "destroy", text: "حذف" }], title: "عملیات", width: "160px" }],
messages: {
editable: {
cancelDelete: "لغو",
confirmation: "آیا مایل به حذف این رکورد هستید؟",
confirmDelete: "حذف"
},
commands: {
create: "افزودن ردیف جدید",
cancel: "لغو کلیهی تغییرات",
save: "ذخیرهی تمامی تغییرات",
destroy: "حذف",
edit: "ویرایش",
update: "ثبت",
canceledit: "لغو"
}
},
editable: "popup"
});
});
在update
功能person
参数,我可以通过访问更改的行:
person.models[0]
它给了我:
Object {ID:1,Name:"pejman",Family:"kam",Tel:"098787887"}
所以我想这个数据发送到服务器,所以我在GridController
一个动作:
[HttpPost]
public void Update(TblPerson person)
{
//do update
}
做这件事,我尝试:
url: function (person) {
return "/Grid/Update/" + JSON.stringify(person.models[0])
},
的更新方法
,但它不不行,我该怎么办? 注:当我在网络上面使用的浏览器选项卡给我Bad Reuest
错误:
URL:http://localhost:2145/Grid/Update/%7B%22ID%22:1,%22Name%22:%22pejman%22,%22Family%22:%22kam%22,%22Tel%22:%22098787878%22%7D
Status Code:400 Bad Request
这将无法正常工作,因为他将JSON附加到URL,它不会通过POST调用发送数据。 – jorgonor
他只是展示了他所尝试的内容,但是他的顶部代码正在与此合作。我正在使用相同的。 – Ademar
对。我猜MVC它仍然在查询字符串中绑定'models',尽管它被声明为'HttpPost'动作。我没有充分考虑,现在我明白了。 :) – jorgonor