我有一个像这样设置可编辑的网格:
.Editable(e =>
{
e.Enabled(true);
e.Mode(GridEditMode.PopUp);
e.TemplateName("MyEdit");
e.Window(w => w.Title("Gadzooks"));
}
在 MyEdit.cshtml 我有这样的东西:
<div>
@Html.LabelFor(m => m.Type)
@Html.EditorFor(m => m.Type, "MyTypeListEdit", Model.Type);
</div>
最后在编辑器 MyTypeListEdit.cshtml 中:
@model object
@{
string selectedValue = (string)Model;
}
@{
SelectList selectList = new SelectList(
new SelectListItem[] {
new SelectListItem()
{
Text = "Primary",
Value = "Primary",
Selected = true
},
new SelectListItem()
{
Text = "Secondary",
Value = "Secondary"
}
},
"Text",
"Value"
);
@(
Html.Kendo().DropDownListFor(model => model)
.Name("Type")
.BindTo(selectList)
.DataValueField("Value")
.DataTextField("Text")
.Value(selectedValue)
)
}
当模型的类型为次要时,它仍然选择主要。(我假设某处断开连接)。如何获取从另一个模板中引用的编辑器模板,该模板在 Editable() 中设置以实际选择适当的值。Kendo UI 文档很糟糕。