代码之家  ›  专栏  ›  技术社区  ›  obautista

带有JSON的jqGrid正在呈现MVC项目中没有数据的表

  •  1
  • obautista  · 技术社区  · 14 年前

    我的控制器里有下面的代码。jsonData确实会被填充并传递到我的索引中。在逐步遍历代码时,我可以看到jsonData有1行,其中单元格索引0、1、2、3、4填充了数据。我不知道为什么这些数据没有被传递到我的索引页上的javascript并显示在网格中。

    我在这个网站上举了一个例子: http://www.schnieds.com/2010/01/gridview-in-aspnet-mvc.html

    var jsonData = new
            {
                total = totalPages,
                page = page,
                records = totalRecords,
                rows = (
                      from a in activities
                      select new
                      {
                          i = a.ActivityId,
                          cell = new string[] {
                          a.ActivityId.ToString(),
                          a.Date.ToString(),
                          a.Person.Name.ToString(),
                          a.ActivityName.ToString(),
                          a.Hours.ToString()                          
                        }
                      }).ToArray()
            };
    
            // Return the result in json
            return Json(jsonData);
    

    我的索引页中的javascript代码如下所示:

    var gridimgpath = '/Scripts/jqgrid/themes/redmond/images';
        var gridDataUrl = '/Home/JsonActivitiesCollection';
    
        // use date.js to calculate the values for this month
        var startDate = Date.parse('today').moveToFirstDayOfMonth();
        var endDate = Date.parse('today');
    
        jQuery("#list").jqGrid({
            url: gridDataUrl + '?startDate=' + startDate.toJSONString() + '&endDate=' + endDate.toJSONString(),
            datatype: "json",
            mtype: 'GET',
            colNames: ['Activity Id', 'Date', 'Employee Name', 'Activity', 'Hours'],
            colModel: [
              { name: 'ActivityId', index: 'ActivityId', width: 100, align: 'left' },
              { name: 'Date', index: 'Date', width: 100, align: 'left' },
              { name: 'Person.Name', index: 'Person.Name', width: 100, align: 'left' },
              { name: 'ActivityName', index: 'ActivityName', width: 100, align: 'left' },
              { name: 'Hours', index: 'Hours', width: 100, align: 'left' }
              ],              
            rowNum: 20,
            rowList: [10, 20, 30],
            imgpath: gridimgpath,
            height: 'auto',
            width: '700',
            pager: jQuery('#pager'),
            sortname: 'ActivityId',
            viewrecords: true,
            sortorder: "desc",
            caption: "Activities"
        });
    
    1 回复  |  直到 14 年前
        1
  •  1
  •   Oleg    14 年前

    i = a.ActivityId
    

    具有

    id = a.ActivityId