5

I have a Kendo grid set up like so:

@(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))

)

The "State" column consists of a dropdown template that looks like this:

@(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
)

My dropdown shows up properly when I edit or create an item, but when I save the item the dropdown value does not stay in the grid. Is there something else I need to set up in order to do this?

4

3 回答 3

4

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

.Name("States") // Name of the widget should be the same as the name of the property

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

于 2013-12-18T04:35:51.833 回答
3

显然这是一个旧线程,但解决方法是使用 DropDownListFor 方法(与 DropDownList 相对)而不是指定名称。我怀疑 Kendo 会进行一些内部名称匹配以将编辑后的值应用回模型。

@model int // ...or whatever type works for your model

@(Html.Kendo().DropDownListFor(i => i)
    .DataValueField("CODE")
    .DataTextField("NAME")
    .BindTo((System.Collections.IEnumerable)ViewData["States"]))
于 2013-10-29T01:40:10.090 回答
0

我不确定这是否能解决您的问题,但是在我UIHint在模型中设置装饰器EditorTemplateName视图中之前,我的网格的编辑器模板无法正常工作。

例如

public class ParticipatingDentalEE {
   ...

   [UIHint("State")] // this should be the name of your EditorTemplate
   public State State { get; set; }

}

我推测它UIHint用于“查看”模式下的网格,而EditorTemplateName用于“编辑”模式下的网格,两者都需要将两者链接在一起。

于 2013-08-22T17:02:32.397 回答