jQuery kendo 网格弹出编辑器不将下拉值传递给 .net MVC 控制器?
jQuery kendo grid popup editor doesn't pass dropdown values to .net MVC controller?
我正在尝试在 jquery kendo 网格弹出编辑器中编辑一行。但是当我点击更新按钮时,它不会将选定的下拉值提交给控制器,而它会毫无问题地提交其他属性。我尝试了很多例子,但没有一个效果很好。
这是我的代码
var element = $("#grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: '/controller/GetEmployees',
update: {
url: "/controller/UpdateEmployee",
dataType: "json"
},
},
pageSize: 10,
serverPaging: true,
serverSorting: false,
schema: {
model: {
id: "EmployeeID",
fields: {
EmployeeID: { type: "number", editable: false },
EmployeeName: { type: "string", editable: true },
EmployeeStatus: { defaultValue: { ID: 1, Name: "Active" }, editable: true }
}
}
}
},
height: 500,
sortable: false,
pageable: false,
editable: "popup",
toolbar: ["create"],
columns: [
{
field: "EmployeeName",
title: "Employee Name",
width: "110px"
},
{
field: "EmployeeStatus",
title: "Status",
width: "110px",
editor: activeInactiveDropDownEditor,
template: "#=EmployeeStatus.Name#"
},
{
command: "edit",
width: "80px"
}
]
});
});
}
function activeInactiveDropDownEditor(container, options) {
$('<input required name="' + options.field + '" data-bind="ID"/>')
.appendTo(container)
.kendoDropDownList({
//autoBind: true,
dataTextField: "Name",
dataValueField: "ID",
dataSource: {
type: "json",
transport: {
read: "/controller/GetStatusList"
}
}
});
}
有人能找到这里的错误吗?
我认为您的问题出在绑定上,我的意思是,这不仅仅是添加一个带有字段名称的数据属性 bind
,有时将模型绑定到小部件需要一定程度的复杂性。由于我无法重现您的整个代码段,我建议您使用 options.model
来设置 input
值,因此小部件可以使用正确的值进行初始化:
function activeInactiveDropDownEditor(container, options) {
$('<input required name="' + options.field + '" value="' + options.model.ID + '" />')
如果这不起作用,请设置 value
初始参数或类似参数。
终于找到解决办法了。我刚刚修改了类型为 属性 的更新请求,现在它运行良好。
update: {
type: 'post', // just added this and works well
url: "/controller/UpdateEmployee",
dataType: "json"
},
我正在尝试在 jquery kendo 网格弹出编辑器中编辑一行。但是当我点击更新按钮时,它不会将选定的下拉值提交给控制器,而它会毫无问题地提交其他属性。我尝试了很多例子,但没有一个效果很好。 这是我的代码
var element = $("#grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: '/controller/GetEmployees',
update: {
url: "/controller/UpdateEmployee",
dataType: "json"
},
},
pageSize: 10,
serverPaging: true,
serverSorting: false,
schema: {
model: {
id: "EmployeeID",
fields: {
EmployeeID: { type: "number", editable: false },
EmployeeName: { type: "string", editable: true },
EmployeeStatus: { defaultValue: { ID: 1, Name: "Active" }, editable: true }
}
}
}
},
height: 500,
sortable: false,
pageable: false,
editable: "popup",
toolbar: ["create"],
columns: [
{
field: "EmployeeName",
title: "Employee Name",
width: "110px"
},
{
field: "EmployeeStatus",
title: "Status",
width: "110px",
editor: activeInactiveDropDownEditor,
template: "#=EmployeeStatus.Name#"
},
{
command: "edit",
width: "80px"
}
]
});
});
}
function activeInactiveDropDownEditor(container, options) {
$('<input required name="' + options.field + '" data-bind="ID"/>')
.appendTo(container)
.kendoDropDownList({
//autoBind: true,
dataTextField: "Name",
dataValueField: "ID",
dataSource: {
type: "json",
transport: {
read: "/controller/GetStatusList"
}
}
});
}
有人能找到这里的错误吗?
我认为您的问题出在绑定上,我的意思是,这不仅仅是添加一个带有字段名称的数据属性 bind
,有时将模型绑定到小部件需要一定程度的复杂性。由于我无法重现您的整个代码段,我建议您使用 options.model
来设置 input
值,因此小部件可以使用正确的值进行初始化:
function activeInactiveDropDownEditor(container, options) {
$('<input required name="' + options.field + '" value="' + options.model.ID + '" />')
如果这不起作用,请设置 value
初始参数或类似参数。
终于找到解决办法了。我刚刚修改了类型为 属性 的更新请求,现在它运行良好。
update: {
type: 'post', // just added this and works well
url: "/controller/UpdateEmployee",
dataType: "json"
},