网格不在kendoGrid中填充

时间:2014-12-13 07:16:24

标签: asp.net-mvc asp.net-mvc-4 razor kendo-ui

我正在使用MVC 4和kendo UI进行网格填充。但网格填充不正确。

这是我的观点:

<script type="text/javascript">

        $.ajax({
            url: '@Url.Action("Employee_Read", "UserSummary")',
            type: 'GET',
            dataType: "json",
            Async: true,
            success: function (data, textStatus, xhr) {
                var dataloc = data;



                var element = $("#grid4").kendoGrid({
                    dataSource: {
                        data: dataloc,
                        schema: {
                            model: {
                                fields: {
                                    userDetailsId: { type: "number", editable: false },
                                    name: { type: "string", editable: false },
                                    roleId: { type: "string", editable: false },
                                    emailId: { type: "string", editable: false }
                                }
                            }
                        }
                    }
                });
            }
        });
    </script>

Conroller;

 [HttpGet]
    public ActionResult Employee_Read([DataSourceRequest]DataSourceRequest request)
    {
        using (var emp = new MockProjectAkarshEntities1())
        {
          IQueryable<tbl_UserDetails> userDetails = emp.tbl_UserDetails;


            DataSourceResult result = userDetails.ToDataSourceResult(request);

            return Json(result,JsonRequestBehavior.AllowGet);


        }

在输出中我得到类似&#34; [object] [object]&#34;从数据库返回的表中没有行。网格的骨架即将到来但不是数据。我是MVC和剑道的新手。请帮帮我。

1 个答案:

答案 0 :(得分:0)

您收到的数据应以{"Data":开头。只需将代码从var dataloc = data;更改为var dataloc = data.Data;,只需访问UserSummary / Employee_Read即可确认。

您也可以稍后设置dataSource(如果您喜欢在某个阶段)

<script type="text/javascript">
$.ajax({
    url: '@Url.Action("Employee_Read", "UserSummary")',
    type: 'GET',
    dataType: "json",
    Async: true,
    success: function (data, textStatus, xhr) {
        var dataloc = data.Data;
        var element = $("#grid4").kendoGrid({
            dataSource: {
                // data: dataloc,
                schema: {
                        model: {
                            fields: {
                                userDetailsId: { type: "number", editable: false },
                                name: { type: "string", editable: false },
                                roleId: { type: "string", editable: false },
                                emailId: { type: "string", editable: false }
                            }
                    }
                }
            }
        });

        // create data source using the data received  
        var ds = new kendo.data.DataSource({
                        data: dataloc
                     });
        $('#grid4').data('kendoGrid').setDataSource(ds);
    }
});
</script>