我在.net MVC 使用 Kendo Ui的Grid插件,Controllers中家DataTable数据序列化Json传递View不显示数据

BreveYoung 发布于 2013/04/17 13:18
阅读 4K+
收藏 0

我在.net MVC 使用 Kendo Ui的Grid插件,Controllers中家DataTable数据序列化Json传递View不显示数据。我的Controllers如下:  public JsonResult IndexJsonTable(KendoGridRequest request, string keywd)
        {
            string[] keywdInfo = keywd.Split('#');
            string startTime = string.Empty;
            string endTime = string.Empty;
            if (keywdInfo != null && keywdInfo.Length > 0)
            {
                startTime = string.IsNullOrEmpty(keywdInfo[0]) ? DateTime.Now.AddDays(-4).ToString() : keywdInfo[0];
                endTime = string.IsNullOrEmpty(keywdInfo[1]) ? DateTime.Now.ToString() : keywdInfo[1]; ;
            }
            DataTable DataList = new DataTable();
            DbCommand dc = new DbCommand(System.Data.CommandType.StoredProcedure);
            dc.CommandText = "P_FL_Manage_Search_Router";
            dc["FlightStartDate"] = startTime;
            dc["FlightEndDate"] = endTime;
            DataSet ds = null;
            ds = dc.Execute();
            DataList = ds.Tables[0];
            return Json(JsonConvert.SerializeObject(DataList, new DataTableConverter()));
        }

在View中我的写法是:

 @section Scripts
{
        <script>
            $(function () {
                //建立数据源对象
                var dataSrc = new kendo.data.DataSource({
                    transport:
                        {
                            read:
                                {
                                    type: "POST",
                                    url: "/OrderRelease/IndexJsonTable",
                                    dataType: "json",
                                    data:
                                    {
                                        //额外传至后方的参数
                                        keywd: function () {
                                            return $("#StartDatepicker").val() + '#' + $("#EndDatepicker").val();
                                        }
                                    }
                                }
                        },
                    schema: {
                        model: {
                            fields: {
                                OrderRelease_GID: { type: "string" },
                                SourceLocation_GID: { type: "string" },
                                MawbDestAirport: { type: "string" }
                            }
                        }
                    },
                    pageSize: 30,
                    serverPaging: true,
                    serverSorting: true
                });
                $("#grid").kendoGrid({
                    dataSource: dataSrc,
                    height:300,
                    sortable: true,
                    filterable: true,
                    columnMenu: true,
                    scrollable: {
                        virtual: true
                    },
                    //pageable: true,
                    columns: [
                        {
                            field: "OrderRelease_GID",
                            title: "订单号",
                            width: 100
                        },
                        {
                            field: "SourceLocation_GID",
                            title: "始发港",
                            width: 100
                        },
                        {
                            field: "MawbDestAirport",
                            title: "目的港",
                            width: 100
                        }
                    ]
                });
                //按下查询钮
                $("#bQuery").click(function () {
                    //要求数据源重新读取(并指定切至第一页)
                    dataSrc.read({ page: 1, skip: 0 });
                    //Grid重新显示数据
                    $("#grid").data("kendoGrid").refresh();
                });
            });
        </script>}    求大神帮解决下,谢谢,急!!!再次感谢

加载中
0
William
William

不显示, 看下数据有没有返回不就行了?

没返回在controller里找原因, 返回了看是否json格式不对..

B
BreveYoung
如果我Json(List<T>)就正常显示了
0
龅牙猫
龅牙猫
学习了,共享一个 Kendo UI最新版
0
吕勇
楼主你最后用datatable绑定成功没?
0
Neoman
Neoman
我最近也在研究kendo ui,有个疑问是: 如何引入指定功能的模块js呢?kendo.web.min.js 太大,很多功能用不上
返回顶部
顶部