使用编辑器下拉列表值更新Kendo网格

Goo*_*ose 5 asp.net-mvc mvc-editor-templates razor drop-down-menu kendo-grid

我有一个剑道网格设置如下:

@(Html.Kendo().Grid<ParticipatingDentalEE>()
.Name("DentalEE")
.Columns(columns =>
{
    columns.Bound(p => p.State).Title("State").Width(150).EditorTemplateName("State");
    columns.Bound(p => p.Count).Title("Count").Width(150);
    columns.Command(c => { c.Edit(); c.Destroy(); });
})
.DataSource(dataSource => dataSource
    .Ajax()           
    .Model(m => {
        m.Id(p => p.State);
        m.Field(p => p.State).Editable(true);
        m.Field(p => p.Count).Editable(true).DefaultValue("");
    })
    .Create(update => update.Action("EditingInline_Create", "Dental"))
    .Read(read => read.Action("EditingInline_Read", "Dental"))
    .Update(update => update.Action("EditingInline_Update", "Dental"))
    .Destroy(update => update.Action("EditingInline_Destroy", "Dental"))
)
//.Scrollable()
//.Sortable()
.Editable(e => e.Mode(GridEditMode.InLine))
Run Code Online (Sandbox Code Playgroud)

)

"状态"列包含一个下拉模板,如下所示:

@(Html.Kendo().DropDownList()
    .Name("States") // Name of the widget should be the same as the name of the property
    .DataValueField("CODE") // The value of the dropdown is taken from the EmployeeID property
    .DataTextField("NAME") // The text of the items is taken from the EmployeeName property
    .BindTo((System.Collections.IEnumerable)ViewData["States"]) // A list of all employees which is populated in the controller
)
Run Code Online (Sandbox Code Playgroud)

当我编辑或创建项目时,我的下拉列表正确显示,但是当我保存项目时,下拉值不会保留在网格中.为了做到这一点,我还需要设置其他东西吗?

Elr*_*ynn 4

正如你在自己的评论中所说,

.Name("States") // Name of the widget should be the same as the name of the property
Run Code Online (Sandbox Code Playgroud)

也就是说,它必须与列名匹配,并且列名是“State”而不是“States”。