为什么我的jqgrid没有显示任何数据? - javascript

我想使用完整的jqgrid,但无法正常工作。它不显示任何数据,但控制器操作将返回值。这是我的项目中使用的控制器动作代码。我的目的是在jqgrid中使用传呼机。请帮助我,我需要在mvc中使用jqgrid的一些解决方案和提示。

 public ActionResult itemList(jqGridViewModel jqGridParameters)
        {
            var item = from t in db.tbl_Item select t;
            var count = item.Count();
            int pageIndex = jqGridParameters.page;
            int pageSize = jqGridParameters.rows;
            int startRow = (pageIndex * pageSize) + 1;
            int totalRecords = count;
            int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
            var result = new
            {
                total = totalPages,
                page = pageIndex,
                records = count,
                rows = item.Select(x => new
                {
                    x.id,
                    x.itemcode,
                    x.name,
                    x.qtyLimit,
                    x.Quantity,
                    x.sellingPrice,
                    x.supplier,
                    x.unitType,
                    x.vat,
                    x.batchno,
                    x.brand,
                    x.buyingPrice,
                    x.catg
                }
                                         ).ToArray()
                       .ToPagedList(pageIndex, pageSize)
                       .Select(x => new
                       {
                           id = x.id,
                           cell = new string[] { x.id.ToString(),  
                                                            x.name,   
                                                            x.itemcode,                  
                    Convert.ToString(x.qtyLimit),
                    x.Quantity.ToString(),
                    x.sellingPrice.ToString(),
                    x.supplier,
                    x.unitType,
                    x.vat.ToString(),
                    x.batchno,
                    x.brand,
                    x.buyingPrice.ToString(),
                    x.catg 
                           }
                       }
                              ).ToArray()
            };
            return Json(result, JsonRequestBehavior.AllowGet);
        }

而我的查看代码

jQuery("#list").jqGrid({
            cache: false,
            async: false,
            url: '/Settings/itemList/',
            datatype: 'json',
            mtype: 'GET',


            colNames: ['New Item', 'Batch No', 'Supplier', 'Unit', 'B. Price', 'S. Price','Item Code','Vat','Limit'],
            colModel: [

                             { name: 'name', index: 'name', width: 110, align: 'center' },
                             { name: 'batchno', index: 'batchno', width: 110, align: 'center' },
                             { name: 'supplier', index: 'supplier', width: 110, align: 'center' },
                             { name: 'unitType', index: 'unitType', width: 110, align: 'center', editoptions: { readonly: 'readonly' } },
                             { name: 'buyingPrice', index: 'buyingPrice', width: 110, align: 'center', editoptions: { readonly: 'readonly' } },
                             { name: 'sellingPrice', index: 'sellingPrice', align: 'center' },
                             { name: 'itemcode', index: 'itemcode', width: 110, align: 'center'},
                             { name: 'vat', index: 'vat', width: 110, align: 'center', editoptions: { readonly: 'readonly' } },
                             { name: 'qtyLimit', index: 'qtyLimit', align: 'center' }

            ],

            pager: jQuery('#pager'),
            rowNum: 15,

            rowList: [5, 10, 20, 50],
            sortname: 'iid',
            sortorder: "desc",
            viewrecords: true,
            width: 960,
            height: 200,
            loadOnce: true,
            imgpath: '/scripts/themes/coffee/images',
            caption: 'Stock Information',
            jsonReader: {
                root: "Data",
                page: "CurrentPage",
                total: "TotalPages",
                records: "TotalRecords",
                repeatitems: false,
                id: "0"
            },
            recordtext: "Products {0} - {1} of {2}",
            rownumbers: true,
            pagerpos: 'center'
     });

参考方案

您可以这样定义JsonReader

jsonReader: {
                root: "Data",
                page: "CurrentPage",
                total: "TotalPages",
                records: "TotalRecords",
                repeatitems: false,
                id: "0"
            },

在控制器端,您可以将数据传递给具有以下属性的匿名对象:

var result = new
            {
                total = totalPages,
                page = pageIndex,
                records = count,
                 ...
            }

您的属性名称应与您在JsonReader中定义的名称相同

如果我得到url(''),我该如何使用另一个URL - javascript

我是新手,正在写这篇文章,但是如果源上没有图像,那么我只有空白。有人可以告诉我,如果我正在获取背景图像,如何获取/images/no-image.jpg:url();这是我的代码:<div class="uk-clearfix uk-position-relative"> <div class="recipeb…

对ID为'abc%'的dom执行操作 - javascript

我想对ID为'abc%'的DOM进行一些操作<a id='abc1'></a> <a id='abc2'></a> <a id='abc3'></a> <a id='abc4'></a>…

Jsonp没有出现``访问控制允许来源''错误 - javascript

在我的PHP中,我喜欢这样来回显jsonp类型的“ json数据”echo $_GET['callback'] . '('.json_encode($arr).')'; 在我的js(angularjs)中,$http.get('http://example.com/app/?callbac…

在JavaScript函数中转义引号 - javascript

我正在尝试将变量传递给javascript函数。根据用户的选择,它可以是文本或图像。这里已经讨论了类似的问题,但我无法解决。在php中,我这样编码:if ($choice == 1) { $img = '<img src = "../folder/'.$_SESSION["img"].'�…

如何调用超链接单击中包含单引号的消息的JavaScript警报? - javascript

我陷入了javascript问题。我正在使用C#编写可以调用javascript来显示警报消息的超链接。请参阅下面的代码以了解它是如何完成的:首先,这是C#从服务器端编写的代码://Server side code string myHyperlink = "<a href='#' onclick=\"alert…