2013-08-07 115 views
0

我一直在使用asp.net mvc4和剑道的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() 
     { 

     } 
    } 
} 

回答

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。

+0

我想你的答案应该可以工作,但实际上我的问题是我需要绑定一个模型,我使用一个单独的类创建..请参考我提到的最后一个问题的模型类的代码,然后请告诉我怎么可以我将它绑定到网格.. – sanzy

+0

就像我在我的回答中提到的那样,您将需要使用Razor创建网格 - 我之前没有这样做。看看他们的文档。 :) – Jeff

+0

如果是这样,你可以请给我电话的方式,我可以绑定模型,如果我用剃刀创建网格..请帮助我,因为我是新来的.. – sanzy