我的jqgrid总是空着

时间:2016-04-09 05:52:05

标签: jqgrid-asp.net

我不知道为什么我的网格总是空着。

这是我的person.js javascript文件。

$(function () {    
$("#grid").jqGrid({
    url: "/Passenger/GetPassenger",
    //ajaxGridOptions: { contentType: "application/json" },
    //async:false,
    datatype: 'json',
    mtype: 'Get',
    colNames: ['Id', 'Name', 'Contact Number', 'City'],

    colModel: [
        { key: true, name: 'pId', index: 'pId' },
        { key: false, name: 'name', index: 'name', editable: true },
        { key: false, name: 'contactNo', index: 'contactNo', editable: true },
        { key: false, name: 'City', index: 'City', editable: true },
    ],
    pager: jQuery("#pager"),
    rowNum: 10,
    rowList: [5, 10, 15, 20],
    height: '100%',
    viewrecords: true,
    caption: "Person List",
    emptyrecords: "No records to display",
    jsoneader: {
        root: "Rows",
        page: "page",
        total: "total",
        records: "records",
        repeatitems: false,
        id: "0"

    },

    autowidth: true,
    multiselect: false

});

这是我的控制器名为Passenger

mydbEntities db = new mydbEntities();
 public ActionResult Index()
    {
        return View();
    }
    public JsonResult GetPassenger(string sidx, string sord, int page, int rows)
    {
        int pageIndex = Convert.ToInt32(page) - 1;
        int pageSize = rows;
        var personList = db.nPassenger9864900.ToList();
        int totalRecords = personList.Count();
        var totalPages = (int)Math.Ceiling((float)(totalRecords) / (float)rows);
        if (sord.ToUpper() == "DESC")
        {
            personList = personList.OrderByDescending(s => s.name).ToList();
            personList = personList.Skip(pageIndex * pageSize).Take(pageSize).ToList();
        }
        else
        {
            personList = personList.OrderBy(s => s.name).ToList();
            personList = personList.Skip(pageIndex * pageSize).Take(pageSize).ToList();
        }
        var jsonData = new
        {
            total = totalPages,
            page,
            records = totalRecords,
            Rows = personList
        };
        return Json(jsonData, JsonRequestBehavior.AllowGet);
    }

我的网格总是空着。但是json数据正在正确地返回数据。

0 个答案:

没有答案