I've been following the sample posted here https://docs.telerik.com/aspnet-core/html-helpers/data-management/grid/templates/editor-templates for creating a drop down list editor for the grid.
Initially the column will display fine, but as soon as I try to make the grid editable the entire grid breaks and displays nothing, not even an error message or anything.
@(Html.Kendo().Grid<TestTelerikGrid.Models.ActualExpenditureDto>() .Name("grid") .Columns(columns => { columns.Bound(c => c.Quantity); columns.Bound(c => c.RawCostRate); columns.Bound(c => c.ExpenditureTypeOption).ClientTemplate("#=ExpenditureTypeOption.Name#").Sortable(false).Width(180); }) .Editable(editable => editable.Mode(GridEditMode.InCell)) .Sortable() .Filterable() .DataSource(dataSource => dataSource .Ajax() .Sort(sort => sort.Add("Id").Ascending()) .ServerOperation(false) .Batch(true) .Model(model => { model.Id(r => r.Id); }) .Read(read => read.Action("Expenditure_Read", "Home")) ))
public class ActualExpenditureDto{ public int Id { get; set; } [Display(Name = "Quantity")] public string Quantity { get; set; } [Display(Name = "Raw Cost Rate")] public string RawCostRate { get; set; } [UIHint("ExpenditureTypeEditor")] [Display(Name = "Expenditure Type")] public ExpenditureTypeModel ExpenditureTypeOption { get; set; }}
public class ExpenditureTypeModel{ public int Id { get; set; } public string Name { get; set; }}
Controller:
public IActionResult Index(){ ViewData["lookupExpenditureType"] = GetExpenditureTypes(); return View();}public ActionResult Expenditure_Read([DataSourceRequest] DataSourceRequest request){ List<ActualExpenditureDto> dtos = new List<ActualExpenditureDto>(); ActualExpenditureDto dto = new ActualExpenditureDto(); dto.Id = 1; dto.Quantity = "3"; dto.RawCostRate = "7"; dto.ExpenditureTypeOption = GetExpenditureTypes().First(); dtos.Add(dto); dto = new ActualExpenditureDto(); dto.Id = 1; dto.Quantity = "55"; dto.RawCostRate = "98"; dto.ExpenditureTypeOption = GetExpenditureTypes().Last(); dtos.Add(dto); var toReturn = Json(dtos.ToDataSourceResult(request)); return toReturn;}private List<ExpenditureTypeModel> GetExpenditureTypes(){ List<ExpenditureTypeModel> expTypes = new List<ExpenditureTypeModel>(); ExpenditureTypeModel typ = new ExpenditureTypeModel(); typ.Id = 1; typ.Name = "Type 1"; expTypes.Add(typ); typ = new ExpenditureTypeModel(); typ.Id = 2; typ.Name = "Type 2"; expTypes.Add(typ); return expTypes;}
ExpenditureTypeEditor.cshtml
@using Kendo.Mvc.UI;@(Html.Kendo().DropDownList() .Name("ExpenditureTypeOption") .DataValueField("Id") .DataTextField("Name") .BindTo((System.Collections.IEnumerable)ViewData["lookupExpenditureType"]) // A list of all expenditure types which is populated in the controller. )
I have a full sample project which shows the problem as well, if the above is not enough, but it is too large to attach here as a zip file, so I'm not sure the best way to share it.
