当我点击"保存更改"为什么我的传输的创建方法没有被调用?网格上的按钮?一切似乎都在工作,除了我的控制器代码创建没有被调用。
剑道代码:
var ds = new kendo.data.DataSource({
transport: {
read: {
cached: false,
url: '@Url.Action("GetListOfFacilities", "Tactic")',
dataType: "json"
}
}
});
var OrgdataSource = new kendo.data.DataSource({
transport: {
read: {
url: '@Url.Action("ReadOrganizations", "Tactic")',
dataType: "json"
},
create: {
url: '@Url.Action("AddOrganization", "Tactic")',
type: "POST",
dataType: "json"
}
},
batch: false
schema: {
model: {
id: "id",
fields: {
id: { type: "string", editable: false },
Name: { type: "string" }
}
}
}
});
$("#FacilityGrid").kendoGrid({
dataSource: OrgdataSource,
autoBind: true,
autoSync: true,
editable: { mode: "inline" },
selectable: true,
toolbar: ["save", "create"],
columns: [
{ command: ["destroy"], title: " ", width: "150px" },
{ field: "Name", title: "Facility Name", editor: OrgDropDownEditor },
]
});
function OrgDropDownEditor (container, options) {
$('<input required data-text-field="Text" data-value-field="Value" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: true,
dataSource: ds
});
}
控制器代码:
[HttpPost]
public JsonResult AddOrganization(SelectListItem selectedOrg)
{
...
}
[HttpGet]
public string GetListOfFacilities()
{
var lst = new List<SelectListItem>();
lst.Add(new SelectListItem() { Value = "1", Text = "Facility 1" });
lst.Add(new SelectListItem() { Value = "2", Text = "Facility 2" });
lst.Add(new SelectListItem() { Value = "3", Text = "Facility 3" });
lst.Add(new SelectListItem() { Value = "4", Text = "Facility 4" });
lst.Add(new SelectListItem() { Value = "5", Text = "Facility 5" });
var json = new JavaScriptSerializer().Serialize(lst);
return json;
}
答案 0 :(得分:0)
尝试从字段对象中删除“id”。如果您已将其指定为模型的ID,则不需要在那里。
答案 1 :(得分:0)
我遇到了同样的问题。我通过为模型字段定义默认值来解决它。在模型中,您应该为Name
字段提供默认值,以防止将null传递给数据源。
schema: {
model: {
id: "id",
fields: {
id: { type: "string", editable: false },
Name: { type: "string" }
}
}
}