返回json文本后Jqgrid未绑定

返回json文本后Jqgrid未绑定,json,jqgrid,Json,Jqgrid,无法绑定我的JQgrid,下面是我的代码: 试图使用Json通过控制器将一些数据绑定到jqgrid,但无法绑定网格。附上我的代码如下 Controller Class: public class TransactionTypeController : Controller { // // GET: /TransactionType/ public ActionResult Index(EMM_New.Models.TransactionTypeModal Trans

无法绑定我的JQgrid,下面是我的代码:

试图使用Json通过控制器将一些数据绑定到jqgrid,但无法绑定网格。附上我的代码如下

Controller Class:

 public class TransactionTypeController : Controller
{
    //
    // GET: /TransactionType/

    public ActionResult Index(EMM_New.Models.TransactionTypeModal TransactionType)
    {
        List<EMM_New.Models.TransactionTypeEntity> lst = TransactionType.GetTransactionType();
        ViewBag.TransactionTypeData = lst;
        return View();
    }

    public ActionResult GetGridData(string sidx, string sord, int page, int rows)
    {
        return Content(JsonHelper.JsonForJqgrid(GetDataTable(sidx, sord, page, rows), rows, GetTotalCount(), page), "application/json");
    }

    public DataTable GetDataTable(string sidx, string sord, int page, int pageSize)
    {
        int startIndex = (page - 1) * pageSize;
        int endIndex = page * pageSize;

        DataTable table = new DataTable();
        table.Columns.Add("CustomerID", typeof(int));
        table.Columns.Add("ContactName", typeof(string));
        table.Columns.Add("Address", typeof(string));
        table.Columns.Add("City", typeof(string));
        table.Columns.Add("PostalCode", typeof(string));
        //
        // Here we add five DataRows.
        //
        table.Rows.Add(25, "Ramesh", "Combivent", "Bangalore", "463456");
        table.Rows.Add(50,  "Sam", "Enebrel", "Hosur", "463456");
        table.Rows.Add(10, "Christoff", "Hydralazine", "Bangalore", "463456");
        table.Rows.Add(21, "Janet", "Combivent",  "Hosur", "463456");
        table.Rows.Add(100, "Melanie", "Dilantin", "Bangalore", "463456");
        return table;
    }

     public int GetTotalCount() {           
        return 10;
    }
}
JsonHelper类:

public class JsonHelper
{
    public static string JsonForJqgrid(DataTable dt, int pageSize, int totalRecords, int page)
    {
        int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
        StringBuilder jsonBuilder = new StringBuilder();
        jsonBuilder.Append("{");
        jsonBuilder.Append("\"total\":" + totalPages + ",\"page\":" + page + ",\"records\":" + (totalRecords) + ",\"rows\"");
        jsonBuilder.Append(":[");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            jsonBuilder.Append("{\"i\":" + (i) + ",\"cell\":[");
            for (int j = 0; j < dt.Columns.Count; j++)
            {
                jsonBuilder.Append("\"");
                jsonBuilder.Append(dt.Rows[i][j].ToString());
                jsonBuilder.Append("\",");
            }
            jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
            jsonBuilder.Append("]},");
        }
        jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
        jsonBuilder.Append("]");
        jsonBuilder.Append("}");
        return jsonBuilder.ToString();
    }
}
视图:

能够看到Jqgrid,但数据没有填充…我正在做的工作。请帮我整理一下。

datatHomeype:'json'

应为数据类型:“json”

尝试按以下方式更改json:

{"total":1,"page":"1","records":10,"rows":[{"cell":["25","Ram","Combivent","Bangalore","463456"]}]}

是否从/TransactionType/GetGridData/?返回了任何json数据?是的,返回了一些数据…..介意显示数据吗?也许json数据的格式是错误的。{total:1,page:1,records:10,rows:[{CustomerID:25,ContactName:Ramesh,Address:Combivent,City:Bangalore,PostalCode:463456},{CustomerID:50,ContactName:Sam,Address:Enebrel,City:Hosur,PostalCode:463456},{CustomerID:10,ContactName:Christoff,Address:Hydralazine,City:Bangalore,PostalCode:463456},{客户ID:21,联系人姓名:Janet,地址:Combivent,城市:Hosur,邮编:463456},{客户ID:100,联系人姓名:Melanie,地址:Dilantin,城市:班加罗尔,邮编:463456}]我在这里尝试了我的输出Json文本,无论它是否有效。它说它的有效Json:@user3015994请使用注释或编辑您的问题以获得后续问题,而不是编辑答案本身。
{"total":1,"page":"1","records":10,"rows":[{"cell":["25","Ram","Combivent","Bangalore","463456"]}]}