0

下面是通过 Ajax 绑定到 WebAPI 的 MVC Kendo UI Grid 示例。WebAPI 使用 OpenAccess ORM 作为数据模型。下面的代码根据模型使用自动生成的列加载网格,成功调用 WebAPI 并以 JSON 格式返回数据,如下所示。

问题似乎出在网格数据绑定中。数据在网格中不可见,但列已成功加载。MVC 代码中缺少什么?

JSON数据:

[{"DC_ID":51234,"DATAACCESS_ID":79238,"MASTERDATA_FLG":"Y","INPUT_TYPE_CD":"QRY","FILE_PATH":"D:\","DESCR":"AAA 数据捕获", "STATUS":"A","CREATED_BY":"SYSTEM","CREATED_DTTM":"01-JAN-2013"},{"DC_ID":79238,"DATAACCESS_ID":79238,"MASTERDATA_FLG":"Y", "INPUT_TYPE_CD":"QRY","FILE_PATH":"D:\","DESCR":"TEST DATA CAPTURE","STATUS":"A","CREATED_BY":"SYSTEM","CREATED_DTTM":"01 -2013 年 1 月"}]

MVC 代码:

@(Html.Kendo().Grid<eConverge.DomainModel.Datacapture>()
      .Name("Grid")
      .Columns(columns =>
      {
          columns.AutoGenerate(true);
      })
      .ToolBar(tools =>
      {
          tools.Create();
      })
      //.Sortable()
      //.Pageable()
      //.Filterable()
      .DataSource(dataSource => dataSource
        .Ajax()
            .Model(model =>
            {
                model.Id(p => p.DC_ID);
            })
            .Read(read => read.Url("http://localhost/econ/econ.webapi/api/datacaptures").Type(HttpVerbs.Get))
            .Create(create => create.Url("http://localhost/econ/econ.webapi/api/datacaptures").Type(HttpVerbs.Post))
            .Update(update => update.Url("http://localhost/econ/econ.webapi/api/datacaptures").Type(HttpVerbs.Put))
            .Destroy(destroy => destroy.Url("http://localhost/econ/econ.webapi/api/datacaptures").Type(HttpVerbs.Delete))      
      )
)
4

1 回答 1

1

将网格绑定到 Web API 控制器需要更多代码。我建议检查以下资源:

http://www.kendoui.c​​om/blogs/teamblog/posts/12-11-29/the_facts_on_using_kendo_ui_with_asp_net_webapi.aspx

http://www.kendoui.c​​om/code-library/mvc/grid/binding-to-a-web-apicontroller.aspx

于 2013-05-14T13:41:31.487 回答