Kendo UI MVC 网格看不到 Model.Columns 数据
嘿,我只使用 kendo ui asp.net mvc 版本2022.r1.sp1,我已经填充了一个带有一排的网格:
上面的屏幕截图网格仅在我用来填充以上网格的代码中评论 foreeach 语句时才能起作用
@(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);
}
)
)
)
:
无法在null引用上执行运行时绑定
这没有任何意义,因为我知道网格中至少有1行数据。
我最初使用代码在这里有点过时。我还看到了此 demo 来自Telerik的演示网站,但这似乎只是在使用 jQuery < /strong>而不是 asp.net mvc ?
我的目标是查看当前行是什么类型(在上面的图像中,将是 4 ,它表明仅数字值)并更改 EditOrteMplateName 以反映这一点。对于此列,将有不同类型的模式,因此我需要动态 更改行编辑每个行的编辑类型的原因。
那么,我在这里想念或做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论