当尝试将 Telerik 网格的编辑模式更改为“InLine”以外的任何模式时,我收到有关传递错误模型类型的错误

发布于 2024-12-24 20:31:29 字数 1185 浏览 4 评论 0原文

我像这样创建网格:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘴硬脾气大 2024-12-31 20:31:29

我想这是因为您作为模型传递的日期不可为空,而模型所需的日期可为空,请在将模型类型更改为“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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文