【发布时间】:2015-05-22 06:38:02
【问题描述】:
我创建了一个 DropDownList EditorTemplate 用于网格内联编辑成功。现在我想在多个列(同一个网格)和/或具有不同网格的不同视图中重用这个模板。
到目前为止,我发现如果我在模板中省略下拉列表的“名称”,那么模板会自动绑定到网格中引用它的那个列(使用.EditorTemplateName(...))。然而,还有其他的东西应该首先参数化(显式或隐式)下拉数据源。
问:一个网格中有很多下拉菜单,如何参数化下拉数据源以防止复制和粘贴 DropDownListTemplate.cshtml 多次?
Q:在多列多视图中使用这个模板一般如何参数化?
观点:
@(Html.Kendo().Grid<Enumeration>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(e => e.Locale).Width(200)
.EditorTemplateName("DropDownListTemplate");
// columns.Bound(e => e.OtherColumn).Width(200)
// .EditorTemplateName("DropDownListTemplate", ???);
...和名为 DropDownListTemplate.cshtml 的模板放在 /Views/Shared/EditorTemplates 中
@model string
@(Html.Kendo()
.DropDownListFor(m => m)
.BindTo(ViewBag.LocaleDropDownListDataSource) // <- Having many dropdown in one grid, how to parameterize this, without copy and paste the DropDownListTemplate.cshtml zillon times?
//.OptionLabel("Select Locale")
.DataValueField("Locale")
.DataTextField("Value")
//.Name("Locale") // Omitting this binds the template automatically to the referring column in the grid. Using a custom .Name, what is not a column name in the grid ruins the working
)
【问题讨论】:
标签: asp.net-mvc kendo-ui kendo-grid kendo-asp.net-mvc