【问题标题】:how to bind model to kendo grid datasource如何将模型绑定到剑道网格数据源
【发布时间】:2013-08-08 09:35:43
【问题描述】:

我已经使用 asp.net mvc4 和 kendo ui 工具开发了一个 Web 应用程序..

在那里我需要直接将模型绑定到网格数据源或架构,而不在架构中创建字段..

这是我的网格的代码..

function LoadGridView() {

        dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "Items/ReadItemDetails",
                    dataType: "json"
                },
                create: {
                    url: "Items/InsertItemDetails",
                    dataType: "json"
                },
                update: {
                    url: "Items/UpdateItemDetails",
                    Type: "POST",
                    dataType: "jsonp"
                },
                destroy: {
                    url: "Items/DeleteItemDetails",
                    dataType: "json"
                }
            },

            batch: true,
            pageSize: 30,
            schema: {
                model: {
                    id: "ItmKy",
                    fields: {
                        ItmCd: { editable: true, nullable: true },
                        ItmNm: { editable: true, nullable: true },
                        Unit: { editable: true, nullable: true },
                        isAct: { editable: true, nullable: true }
                    }
                }
            }
        });
}

我需要将模型名称传递给架构而不是这些行

schema: {
                    model: {
                        id: "ItmKy",
                        fields: {
                            ItmCd: { editable: true, nullable: true },
                            ItmNm: { editable: true, nullable: true },
                            Unit: { editable: true, nullable: true },
                            isAct: { editable: true, nullable: true }
                        }
                    }
                }

我试过这样,但网格不工作..

schema: {
                    model: @Model
                }

有人可以帮助我并告诉我如何将模型绑定到架构或数据源如果可能的话..

这里是模型类

namespace KendoModel
{
    public class ItemMas_LookUp 
    {
        public long ItmKy { get; set; }
        public string ItmCd { get; set; }
        public string ItmNm { get; set; }
        public int UnitKy { get; set; }
        public int isAct { get; set; }
        public string Unit { get; set; }

        public ItemMas_LookUp() 
        {

        }
    }
}

【问题讨论】:

    标签: model kendo-ui schema datasource kendo-grid


    【解决方案1】:

    这就是我在纯 JS 中的做法,没有后端组件:

    我的模特:

    var PageItem = kendo.data.Model.define({
        id: "Id"
    });
    

    我的数据源(在同一范围内!):

    var pageItemDs = new kendo.data.DataSource({
        transport: {
            ...
        },
        schema: {
            model: PageItem
        }
    });
    

    如果您希望使用 ASP.NET 组件,则需要在 Razor 中定义网格本身,您将无法像尝试那样混合 JS 和 Razor。

    【讨论】:

    • 我想你的答案应该有效,但实际上我的问题是我需要绑定一个我使用单独的类创建的模型。请参考我在最后一个问题中提到的模型类的代码,然后请告诉我如何将其绑定到网格..
    • 就像我在回答中提到的那样,您需要使用 Razor 创建网格 - 我以前没有这样做过。查看他们的文档。 :)
    • 如果是这样,如果我用剃刀创建网格,请告诉我绑定模型的方式。请帮助我,因为我是新手。
    • demos.kendoui.com/web/grid/remote-data.html - 单击演示下方的 ASP.NET MVC 链接。有关于如何做到这一点的示例代码。
    猜你喜欢
    • 1970-01-01
    • 2017-09-26
    • 2017-09-25
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多