当尝试将 Telerik 网格的编辑模式更改为“InLine”以外的任何模式时,我收到有关传递错误模型类型的错误
我像这样创建网格:
Html.Telerik().Grid<myapp.Date>("dates")
.Name("MyGrid")
.Pageable(paging => paging.PageSize(10))
.Sortable()
.Filterable()
.Groupable()
.DataKeys(keys => keys.Add(c => c.id))
.DataBinding(dataBinding =>
{
dataBinding.Ajax()
.Select("_SelectAjaxEditing", "Dates")
.Insert("_InsertAjaxEditing", "Dates")
.Update("_SaveAjaxEditing", "Dates")
.Delete("_DeleteAjaxEditing", "Dates");
})
.ToolBar(commands => commands.Insert())
.Columns(columns =>
{
columns.Bound(o => o.name);
columns.Bound(o => o.date1);
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.Text);
commands.Delete().ButtonType(GridButtonType.Text);
});
})
.Editable(editing => editing.Mode(GridEditMode.InLine))
.Render();
%>
它运行良好,但是如果我将 GridEditMode 更改为 InLine 以外的任何模式,则会出现以下错误:
传入字典的模型项的类型为“myapp.Date”,但是 该词典需要类型的模型项 'System.Nullable`1[System.DateTime]'。
网格中有一个 system.DateTime 字段,这是此错误的原因吗?
I create the grid like so:
Html.Telerik().Grid<myapp.Date>("dates")
.Name("MyGrid")
.Pageable(paging => paging.PageSize(10))
.Sortable()
.Filterable()
.Groupable()
.DataKeys(keys => keys.Add(c => c.id))
.DataBinding(dataBinding =>
{
dataBinding.Ajax()
.Select("_SelectAjaxEditing", "Dates")
.Insert("_InsertAjaxEditing", "Dates")
.Update("_SaveAjaxEditing", "Dates")
.Delete("_DeleteAjaxEditing", "Dates");
})
.ToolBar(commands => commands.Insert())
.Columns(columns =>
{
columns.Bound(o => o.name);
columns.Bound(o => o.date1);
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.Text);
commands.Delete().ButtonType(GridButtonType.Text);
});
})
.Editable(editing => editing.Mode(GridEditMode.InLine))
.Render();
%>
and it runs fine, but if I change the GridEditMode to be anything other than InLine I get the following error:
The model item passed into the dictionary is of type 'myapp.Date', but
this dictionary requires a model item of type
'System.Nullable`1[System.DateTime]'.
There is a system.DateTime field in the grid, is that the reason for this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想这是因为您作为模型传递的日期不可为空,而模型所需的日期可为空,请在将模型类型更改为“DATETIME?”后尝试此操作。
注意:如果您要声明属性,请将其声明为 DateTime?,因为您的字段可为空。
谢谢
,
达瓦尔·舒克拉
I suppose this is because the date you are passing as model is not nullable, while the date required to model is nullable, try this after changing the model type to "DATETIME?".
Note: If you are declaring property declare it as DateTime? as your field is nullable.
Thanks
Regards,
Dhaval Shukla