1 year ago
#382763
StealthRT
Kendo UI MVC grid not seeing Model.Columns data
Hey all I am using Kendo UI for ASP.NET MVC version 2022.R1.SP1 and I have populated a grid with one row:
The above screenshot grid works only when I comment out the FOREEACH statement in the code below I am using to populate that grid above is this:
@(Html.Kendo().Grid<Dtos.ConfigurationItemDto>()
.Name("grbConfigSettings")
.Editable(editable => editable.Mode(GridEditMode.InLine))
.ColumnMenu()
.Filterable()
.ToolBar(t => t.Search())
.Search(s => {
s.Field(o => o.Value, "contains");
})
.Height("90%")
.Selectable(s => s.Mode(GridSelectionMode.Single))
.Resizable(r => r.Columns(true))
.Sortable()
.Pageable(p =>
{
p.Refresh(true);
p.PageSizes((IEnumerable<int>)new List<int> { 50, 100, 250, 500 });
p.PreviousNext(true);
p.Input(true);
p.AlwaysVisible(true);
}
)
.Editable(g=>g.Mode(GridEditMode.InLine))
.Columns(c =>
{
foreach (System.Data.DataColumn column in Model.Columns)
{
switch (column.DataType.ToString())
{
case "System.Int16":
case "System.Int32":
case "System.Int64":
c.Bound(column.ColumnName).EditorTemplateName("Integer");
break;
case "System.Decimal":
case "System.Double":
case "System.Float":
c.Bound(column.ColumnName).EditorTemplateName("Number");
break;
case "System.String":
c.Bound(column.ColumnName).EditorTemplateName("String");
break;
default:
//etc etc
break;
}
}
c.Bound(m => m.Id).Hidden();
c.Bound(m => m.NameSpace);
c.Bound(m => m.Key);
c.Bound(m => m.Type);
c.Bound(m => m.Value);
c.Command(cmd =>
{
cmd.Edit();
});
})
.Scrollable()
.DataSource(
ds => ds
.Ajax()
.PageSize(50)
.Read(read => read.Action("Read", "Configuration"))
.Update(update => update.Action("Update", "Configuration"))
.Model(m =>
{
m.Id(c => c.Id);
m.Field(c => c.Key).Editable(false);
m.Field(c => c.Type).Editable(false);
m.Field(c => c.NameSpace).Editable(false);
m.Field(c => c.Value).Editable(true);
}
)
)
)
Every time I try loading the page I get the error of:
Cannot perform runtime binding on a null reference
Which does not make any sense since I know there are at least 1 row of data in the grid.
I originally used the code here but seeing as it was posted in 2017 - its a little outdated. I have also seen this demo from Telerik's demo site but that seems to just be using jQuery and not ASP.NET MVC?
My goal would be to see what type that current row is (in the image above that would be a 4 which would indicate a numeric only value) and change the EditorTemplateName to reflect this. There will be different types of modes for this column so that is why I am needing to dynamically change that rows edit type for each row.
So, what am I missing or doing wrong here?
c#
kendo-ui
kendo-grid
kendo-asp.net-mvc
mvc-editor-templates
0 Answers
Your Answer