Hi,
I'm having an issue getting a foreign key column to persist in the grid. Here's my grid...
@(Html.Kendo().Grid<GridDataItem>(Model.GridDataItems) .Name("gridDataItems") .Columns(columns => { columns.Bound(model => model.Name); columns.ForeignKey(model => model.ChildDataItemId, Model.AllChildDataItems, "Id", "Value");//.EditorTemplateName("_ForeignKeyDropDown"); columns.Command(command => { command.Edit(); }).Width(172); }) .ToolBar(toolbar => toolbar.Create()) .Editable(editable => editable.Mode(GridEditMode.PopUp)) .DataSource(dataSource => dataSource .Ajax() .PageSize(20) .ServerOperation(false) .Model(model => { model.Id(p => p.Id); }) ) )Here's the controller...
public class GridTestController : Controller { public IActionResult Index() { var viewModel = new GridTestModel { GridDataItems = new List<GridDataItem> { new GridDataItem { Id = 1, Name = "Record 1", ChildDataItemId = 2 }, new GridDataItem { Id = 2, Name = "Record 2", ChildDataItemId = 3 }, new GridDataItem { Id = 3, Name = "Record 3" } } }; return View(viewModel); } }and here's the Model...
public class GridTestModel { public List<GridDataItem> GridDataItems { get; set; } public List<ChildDataItem> AllChildDataItems { get { return new List<ChildDataItem> { new ChildDataItem { Id = 1, Value = "Option 1" }, new ChildDataItem { Id = 2, Value = "Option 2" }, new ChildDataItem { Id = 3, Value = "Option 3" } }; } } } public class GridDataItem { public int Id { get; set; } public string Name { get; set; } public int? ChildDataItemId { get; set; } public ChildDataItem ChildDataItem { get; set; } } public class ChildDataItem { public int Id { get; set; } public string Value { get; set; } }The values for Option 1 and Option 2 can be updated fine (as they're preset with a non-null value) but I'm not able to select a value for the Option 3 record nor am I able to set the foreign key value (ChildDataItemId) for a new record.
Anyone an idea as to why? I've also tried a custom editor template for the drop down field using .ValuePrimitive(true) but this has no effect.
Thanks
Stuart.

