MVC easyUI DatagGrid绑定数据问题

2017-05-06 02:23
使用MVC easyui datagrid绑定数据,为什么页面显示的是json字符串,不是列表
MVC easyUI DatagGrid绑定数据问题0

控制器中获取列表并返回json数据:
 public JsonResult UserList()
        {
            List<UserInfo> list = service.UserInfoLoad(1, 3, new UserInfo());
            int rowCount = service.GetRecordCount();

            var json = new
            {
                total = rowCount,
                rows = list.Select(x =>
                    new
                    {
                        UserId = x.UserId,
                        UserName = x.UserName
                    }).ToArray()
            };
            return Json(json, JsonRequestBehavior.AllowGet);
        }

view页面:
<body>
    <table id="userList"></table>
    <div></div>
</body>

使用easyUI绑定数据js:
$('#userList').datagrid({
                url:@Html.Action("UserList","UserInfo"),
                title:'用户列表',
                dataType: "json",
                fit:true,
                rownumbers:true,
                pagination:true,
                method:'get',
                pageSize:20,
                pageList:[10,20,30,40,50],
                pageNumber:1,
                sortName:'UserId',
                sortOrder:'desc',
                columns:[[
                    {field:'UserId',title:'编号'},
                    {field:'UserName',title:'用户名' }
                ]]
            });

回复讨论(解决方案)

把dataType: "json",  去掉。再看看esayui的脚本和样式都引用了没
Easyui/jquery.min.js
Easyui/jquery.easyui.min.js
Easyui/locale/easyui-lang-zh_CN.js
Easyui/themes/default/easyui.css
Easyui/themes/icon.css


看你的JSON数据是没问题,可能是你前台问题

    $('#List2').datagrid({
                title: 'Checkbox selection on DataGrid',
                url: 'GetPurchaseOrder',
                method: 'get', //默认是post,不允许对静态文件访问
                width: '700',
                iconCls: 'icon-save',
                dataType: "json",
                fitColumns: true,
                rownumbers: true, //是否加行号 
                pagination: true, //是否显式分页 
                pageSize: 15, //页容量,必须和pageList对应起来,否则会报错 
                pageNumber: 2, //默认显示第几页 
                pageList: [15, 30, 45],//分页中下拉选项的数值 
                columns: [[
                    { field: 'ck', checkbox: true },
                    { field: 'PKID', title: 'id' },
                    { field: 'REAL_NAME', title: '姓名' },
                    { field: 'MOBILE', title: '手机号码' },
                    { field: 'STAFF_CODE', title: '编号' }                
                ]],
                singleSelect: false, //允许选择多行
                selectOnCheck: true,//true勾选会选择行,false勾选不选择行, 1.3以后有此选项
                checkOnSelect: true //true选择行勾选,false选择行不勾选, 1.3以后有此选项
            });
已解决。。