1

我已经使用 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() 
        {

        }
    }
}
4

1 回答 1

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。

于 2013-08-07T06:30:08.947 回答