关于剑道网格数据绑定的一些困惑

时间:2015-08-05 08:30:26

标签: kendo-ui asp.net-mvc-5

我有一个kendo网格,我动态地调用数据绑定。 以下是代码:

<div id="example">
    <div id="grid"></div>
    <script>
        $(document).ready(function () {


            var _dataSource = new kendo.data.DataSource({
              
                transport: {
                            read: {
                                type: "POST",
                                url: "/Dashboard/GetAttritionEmployeeDetailsWithColl",
                                dataType: "json",
                                contentType: "application/json"
                            },
                            parameterMap: function (options, operation) {
                                return JSON.stringify(options);
                            }
                        },
                        schema: {
                            data: "Data",
                            errors: "Errors",
                            total: "Total",
                            model: {
                                fields: {
                                   
                                    Department: { type: "string" },
                                   
                                }
                            }
                        },
                        pageSize: 20,
                        serverPaging: true,
                        serverFiltering: true,
                        serverSorting: true
            });

         

            $("#grid").kendoGrid({
                dataSource:_dataSource,
                height: 550,
                filterable: true,
                sortable: true,
                pageable: true,
                columns: [{
                    
                        field: "Department",
                        title: "Department"
                }
      
                ]
            });
        });
    </script>
</div>

这是仪表板控制器中使用的功能

  public List<Entity.EmployeeHeadCountResponse> GetAttritionEmployeeDetailsWithColl(Entity.DashboardEmpRequest request)
        {
            try
            {
                employeeHeadCountResponseList = new List<Entity.EmployeeHeadCountResponse>();
                DashboardServiceAgent client = new DashboardServiceAgent();
                request.FlapName = "Attrition";
                request.LoggedInStaffId = "33019";
                request.RoleName = "Administrator";
                 

                client.GetDashboardEmpDetailsWithBytes(request, (s, e) =>
                {

                    if (e.GetType() == typeof(Service.GetDashboardEmpDetailsWithBytesCompletedEventArgs))
                    {
                        Service.GetDashboardEmpDetailsWithBytesCompletedEventArgs err = (Service.GetDashboardEmpDetailsWithBytesCompletedEventArgs)e;

                        if (err.Error == null && err.Result != null)
                        {
                            
                            List<Service.GenericCollection> GenColl = new List<Service.GenericCollection>();
                            byte[] compress = err.Result;
                            GenColl = PayloadHelper.CompressedBytesToObject(compress) as List<Service.GenericCollection>;
                            HierarchyCollection collection = new HierarchyCollection(GenColl);
                           
                            ServiceResult = GenColl;
                            
                            EmpCollection = collection;
                            var mylist = EmpCollection.ToList();
                            
                            if (EmpCollection != null)
                            {
                                dict = new HierarchyCollection().FillForCategoryValues(GenColl);
                                Employee_Read(request2);
                            }
                           
                            
                        }
                       
                    }
                }

             );
                
            }
            catch (System.Exception ex)
            {
                 Common.InsertLogging(ex);
            }
            return employeeHeadCountResponseList;
           
        }

所以在这个函数中它从wcf服务获取返回数据所以这是异步服务第一次它提供空值而第二次它获取值所以每当它获取数据我在这个函数内调用Employee_Read函数。但无法在ken​​do网格中显示数据。 现在我的问题是在这里我必须调用返回json的main函数吗?

1 个答案:

答案 0 :(得分:1)

而不是使用

public List<Entity.EmployeeHeadCountResponse> GetAttritionEmployeeDetailsWithColl(Entity.DashboardEmpRequest request)

使用

public ActionResult GetAttritionEmployeeDetailsWithColl()

并返回Plain Json而不是kendoDataSourceResult,因为你已经将它转换为JavaScript端的kendo数据源你必须使用

return Json(employeeHeadCountResponseList)

这已经足够了。