I have a grid with some columns where one of these columns is a foreignKey column.
I want to show all possible values ββfor this column in a combo box. ViewData["States"]is IList<State>where State has a field Idand a Name.
To do this, I changed the "GridForeignKey.cshtml" template as follows:
@model object
@(
Html.Kendo().ComboBoxFor(m => m)
.BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") +
"_Data"]).Filter(FilterType.Contains).Placeholder("Select...")
)
My view is as follows:
<div class="contentwrapper">
@{
ViewBag.Title = "Home Page";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@(
Html.Kendo().Grid<CustomerModel>()
.Name("Grid")
.Columns(columns => {
columns.Bound(p => p.Name);
columns.ForeignKey(p => p.StateId, (IEnumerable)ViewData["States"], "Id", "Name");
columns.Bound(p => p.StreetAddress).Width(140);
columns.Bound(p => p.Zip).EditorTemplateName("Integer");
columns.Command(command => { command.Edit(); command.Destroy(); });
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Model(model => {
model.Id(c => c.CustomerId);
model.Field(c => c.CustomerId).Editable(false);
model.Field(c => c.Zip).DefaultValue(4444);
}
)
.Create(update => update.Action("EditingInline_Create", "Customer"))
.Read(read => read.Action("EditingInline_Read", "Customer"))
.Update(update => update.Action("EditingInline_Update", "Customer"))
.Destroy(update => update.Action("EditingInline_Destroy", "Customer"))
)
)
</div>
<script type="text/javascript">
function error_handler(e) {
if (e.errors) {
var message = "Errors:\n";
$.e`enter code here`ach(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "\n";
});
}
});
alert(message);
}
}
</script>
Now my problems are:
- My table does not display the selected value for Status.
- When I edit a line, a drop-down field appears and has all the necessary values, but no value is selected. Instead, it always displays placeholder text.
- , , , , (
State, Id Name), - kendo , p => p.State.Id. , StateId. , ?