Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 jqSubGrid未加载数据_Asp.net Mvc 3_Jqgrid_Jqgrid Asp.net_Mvcjqgrid - Fatal编程技术网

Asp.net mvc 3 jqSubGrid未加载数据

Asp.net mvc 3 jqSubGrid未加载数据,asp.net-mvc-3,jqgrid,jqgrid-asp.net,mvcjqgrid,Asp.net Mvc 3,Jqgrid,Jqgrid Asp.net,Mvcjqgrid,我知道很多人都问过同样的问题。我尝试过所有其他建议,但都没有成功。我确信这是我忽略了的事情,我希望有第二双眼睛来帮助我。提前谢谢 我的问题是,主网格负载可以找到。问题出在子电网上 <script type="text/javascript"> jQuery(document).ready(function () { jQuery("#PositionsGrid").jqGrid({ url: '/Position/GetPosition

我知道很多人都问过同样的问题。我尝试过所有其他建议,但都没有成功。我确信这是我忽略了的事情,我希望有第二双眼睛来帮助我。提前谢谢

我的问题是,主网格负载可以找到。问题出在子电网上

<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery("#PositionsGrid").jqGrid({
            url: '/Position/GetPositions?projectid=@Model.ID',
            datatype: 'json',
            mtype: 'POST',
            colNames: ['PositionID', 'ID', 'Job', 'Band', 'Start Date', 'End Date','Current Assignee','Terminated Worker','Status'],
            colModel: [
          { name: 'PositionID', index: 'PositionID', width: 20, align: 'left', hidden: true, sortable: false, search: false,key:true },
          { name: 'DisplayID', index: 'DisplayID', width: 50, align: 'left' },
          { name: 'JobTitle', index: 'JobTitle', width: 100, align: 'left' },
          { name: 'Band', index: 'Band', width: 50, align: 'left' },
          { name: 'StartDate', index: 'StartDate', width: 50, align: 'left', searchoptions: { sopt: ['cn'], dataInit: datePick} },
          { name: 'EndDate', index: 'EndDate', width: 50, align: 'left', searchoptions: { sopt: ['cn'], dataInit: datePick} },
          { name: 'CurrentWorker', index: 'CurrentWorker', width: 100, align: 'left' },
          { name: 'TerminatedWorker', index: 'TerminatedWorker', width: 100, align: 'left' },
          { name: 'Status', index: 'Action', width: 50, align: 'left', search: false}],
            pager: jQuery('#pager'),
            rowNum: 10,
            rowList: [5, 10, 20, 50],
            sortname: 'PositionID',
            sortorder: "asc",
            viewrecords: true,
            autowidth: true,
            subGrid: true,
            subGridRowExpanded: showDetails

        });
        $('#PositionsGrid').jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: 'cn' });
        $("#PositionGrid").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, search: false, refresh: true });
    });

    datePick = function (elem) {
        $(elem).datepicker({ dateFormat: "mm/dd/yy", onSelect: function (dateText, inst) { $("#grid")[0].triggerToolbar(); } });
    };

    function showDetails(subgrid_id, row_id) {

        showSubGrid_AssignmentsGrid(subgrid_id, row_id, "<br><b>Worker History</b><br><br>", "AssignmentsGrid");

    }


    function showSubGrid_AssignmentsGrid(subgrid_id, row_id, message, suffix) {
     var subgrid_table_id;
        subgrid_table_id = subgrid_id + "_t";
        if (message) jQuery('#' + subgrid_id).append(message);
        if (message) jQuery('#' + subgrid_id).append(message);   
        jQuery("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table>");
        jQuery("#" + subgrid_table_id).jqGrid({
            url: "Position/GetAssignmentsByPosition?positionid=" + row_id,
            datatype: "json",
            colNames: ['AssignID', 'JobReqNum', 'WorkerName', 'StartDate', 'EndDate','Status'],
            colModel: [
            { name: "AssignID", index: "AssignID", width: 80},
            { name: "JobReqNum", index: "JobReqNum", width: 130 },
            { name: "WorkerName", index: "WorkerName", width: 80, align: "right" },
            { name: "StartDate", index: "StartDate", width: 80, align: "right" },
            { name: "EndDate", index: "EndDate", width: 100, align: "right" },
             { name: "Status", index: "Status", width: 100, align: "right" }
          ],
            height: '100%',
            rowNum: 20,
            sortname: 'AssignID',
            sortorder: "asc"
                });

    }

</script>

您还需要传递到jqgrid:

            page = numberOfPages
            records = totalRecords,
我个人使用的是:

        var jsonData = new
        {
            total = (totalRecords + rows - 1) / rows,
            page = page,
            records = totalRecords,
            rows = (
                from item in pagedQuery                  
                select new
                {
                    cell = new string[] {       
                       item.value1,
                       item.value2, ....
                    }
                }).ToArray()

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

原来我没有使用JsonRequestBehavior.AllowGet,这就是我出现问题的原因!!
        var jsonData = new
        {
            total = (totalRecords + rows - 1) / rows,
            page = page,
            records = totalRecords,
            rows = (
                from item in pagedQuery                  
                select new
                {
                    cell = new string[] {       
                       item.value1,
                       item.value2, ....
                    }
                }).ToArray()

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