I have grid and form, which are bound to Employee object. It has object property Department. To edit it, I use separate editors, because I didn't find the right format to allow editing in both places.
Usage in form:
i.Add().Field(e => e.DepartmentId).Label("Отдел").EditorTemplateView(Html.Partial("FormEditors/Department"));
Editor of the form's field:
@(Html.Kendo().DropDownList()
.Name("DepartmentId")
.DataTextField("Name")
.DataValueField("Id")
.Filter(FilterType.Contains)
.DataSource(source =>
{
source.Read(read => read.Action("GetDepartments", "Home"));
}))
Usage in grid:
columns.Bound(p => p.Department.Name).Width(230)
.ClientTemplate("#=data.Department?.Name ?? ''#")
.EditorTemplateName("Department")
.Filterable(ftb => ftb.Cell(cell =>
{
cell.Operator("startswith");
cell.ShowOperators(false);
}));
Editor of the grid's column:
@(Html.Kendo().DropDownListFor(m => m)
.DataTextField("Name")
.DataValueField("Id")
.Filter(FilterType.Contains)
.HtmlAttributes(new { data_bind = "value: Department" })
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetDepartments", "Home");
});
}))