JqG​​rid在ASP.NET MVC3中没有显示网格

时间:2014-08-20 09:38:26

标签: c# json asp.net-mvc-3 jqgrid

查看:

      @{
    ViewBag.Title = "TestGrid";
     }


    <link href="@Url.Content("~/Content/JqGrid/jquery-ui-jqgrid.css")" rel="stylesheet" type="text/css" />
     <script src="@Url.Content("~/Scripts/JqGrid/jquery-1.5.2.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/JqGrid/jquery-ui-1.8.7.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/JqGrid/jquery-ui.multiselect.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/JqGrid/jquery.tmpl.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/JqGrid/jquery.jqGrid.locale-en-4.1.2.js")" 
type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/JqGrid/jquery.jqGrid-4.1.2.min.js")" type="text/javascript"></script>


<h2>
    TestGrid</h2>
<h2>
    My Grid Data</h2>
<table id="list">
</table>
<div id="pager">
</div>
<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery("#list").jqGrid({
            url: 'Grid/GridData',
            datatype: 'json',
            colNames: ['COM_NAME', 'COM_CODE', 'DELV_UNITS', 'LOT_SIZE', 'TICK_SIZE', 'TICK_VALUE'],
            colModel: [
        { name: 'COM_NAME', index: 'COM_NAME', width: 90 },
        { name: 'COM_CODE', index: 'COM_CODE', width: 100 },
        { name: 'DELV_UNITS', index: 'DELV_UNITS', width: 80, align: "right" },
        { name: 'LOT_SIZE', index: 'LOT_SIZE', width: 80, align: "right" },
        { name: 'TICK_SIZE', index: 'TICK_SIZE', width: 80, align: "right" },
        { name: 'TICK_VALUE', index: 'TICK_VALUE', width: 150, sortable: false }
    ],
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: '#pager',
            viewrecords: true,
            jsonReader: {
                root: "rows",
                page: "page",
                cell: "cell"
            },
            caption: "JSON Example"
        });
     });
      jQuery("#list").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false });
       </script>

控制器:

public ActionResult GridData(string sidx = "", string sord = "", int page = 1, int rows = 10)
    {
        TestGridModel tstGrid = new TestGridModel();
        tstGrid.listArr = new List<CommodityReport>();
        string conn = ConfigurationManager.ConnectionStrings["DbConnnectionString"].ConnectionString;
        ReportDAL rptDal = new ReportDAL();
        DataTable dt = rptDal.GetCommodity(conn, "");
        //List<string[]> row = new List<string[]>();
        List<Cell> row = new List<Cell>();
        int i = 0;
        foreach (DataRow item in dt.Rows)
        {
            row.Add(new Cell { cell = dt.Rows[i].ItemArray.Select(x => x.ToString()).ToArray() });
            i++;
        }
        var jsonData = new
        {
            total = 1, // we'll implement later 
            page = page,
            records = 3, // implement later 
            rows = row.ToArray()

        };
        return Json(jsonData, JsonRequestBehavior.AllowGet);
    }

结果:

  {"total":1,"page":1,"records":3,"rows":[{"cell":
["WHEAT","WHEAT","1","1.0000","1","100.000000"]},{"cell":["SL10","SILVER","1","1.0000","1","10.000000"]},{"cell":["CL10","CRUDE10","1","0.0100","1","10.000000"]},{"cell":["SL100","SL100OZ","1","0.0010","100","100.000000"]},{"cell":["TOLAGOLD","TOLAGOLD","1","1.0000","10","1.000000"]},{"cell":["JPYUSD","JPYUSD","1","0.0100","10000","10000.000000"]},{"cell":["GOKILO","GOLDKILO","1","1.0000","1","103.260000"]},{"cell":["TG100","TGOLD100","1","1.0000","100","100.000000"]},{"cell":

["TG50","TGOLD50","1","1.0000","50","50.000000"]},{"cell":["RBDPO","PALMOLEIN","1","1.0000","1","669.810000"]},{"cell":["GO","GOLD","1","1.0000","10","10.000000"]},{"cell":["GOD","GOLDOCTDEC","1","1.0000","1","1.000000"]},{"cell":["GSDJ","GOSPDECJAN","1","1.0000","1","1.000000"]},{"cell":["GSMA","GOSPMARAPR","1","1.0000","1","1.000000"]},{"cell":["RI6","RICEIRRI6","1","1.0000","1","250.000000"]},{"cell":["GSGP","GOSPAUGSEP","1","1.0000","1","10.000000"]},{"cell":["MGOLD","MINIGOLD","10","1.0000","10","1.000000"]},{"cell":["BCO","BRENTCRUDE","1","1.0000","1","1.000000"]},{"cell":["PT","PLATINUM","1","1.0000","1","1.000000"]},{"cell":["GSLG","GOSPJULAUG","1","1.0000","1","10.000000"]},{"cell":["PKRUSD","PKRUSD","1000","0.0100","1","10.000000"]},{"cell":["GO1KG","GOLD1KG","1","1.0000","1","103.260000"]},{"cell":["K3M","KIBOR3M","1","0.0100","1","2500.000000"]},{"cell":["TTGOLD","TTGOLD","10","1.0000","1","10.000000"]},{"cell":["CRUDEOIL","CRUDEOIL","1","0.0100","100","100.000000"]},{"cell":["GO100","GO100OZ","1","0.1000","100","100.000000"]},{"cell":["IRRI6W","IRRI6W","1","1.0000","1","250.000000"]},{"cell":["SL500","SL500OZ","1","0.0010","500","500.000000"]},{"cell":["GO1","GO1OZ","1","0.1000","1","1.000000"]},{"cell":["WTI100","WTI100","1","0.0100","100","100.000000"]},{"cell":["CL100","CRUDE100","1","0.0100","1","100.000000"]},{"cell":["EURUSD","EURUSD","1","0.0001","10000","10000.000000"]},{"cell":["GBPUSD","GBPUSD","1","0.0001","10000","10000.000000"]},{"cell":["USDJPY","USDJPY","1","0.0100","10000","10000.000000"]},{"cell":["TGOLD","TGOLD","1","1.0000","10","1.000000"]},{"cell":["SUGAR","SUGAR","1","0.0100","1","10000.000000"]},{"cell":["USCOTTON","USCOTTON","1","0.0100","1","50.000000"]},{"cell":["GO10","GO10OZ","1","0.1000","10","10.000000"]},{"cell":["SLV10","SL10","1","0.0010","10","10.000000"]},{"cell":

["ICT","ICOTTON","1","0.0100","1","50.000000"]},{"cell":["MTGOLD","MTOLAGOLD","1","1.0000","10000","0.001000"]},{"cell":["COPPER","COPPER","1","0.0001","1000","1000.000000"]},{"cell":["BRENT10","BRENT10","1","0.0100","1","10.000000"]},{"cell":["BRENT100","BRENT100","1","0.0100","1","100.000000"]}]}

问题是当我的控制器返回Json时,它只是在网页而不是网格上显示Json。可以帮我解决这个问题吗?

0 个答案:

没有答案
相关问题