0

我有一个必须加载 jqgrid 的 aspx 引擎视图。

但是 jqgrid 没有加载。我尝试使用萤火虫断点,但它也没有命中

在视图中

<asp:Content ID="Content3" ContentPlaceHolderID="MetaContent" runat="server">
<table  id="jqgprojectnew" style="width: 100%">
  </table>
 <script type="text/javascript"> 

var url = '<%#Url.Action("Listmanoj")%>';
    var colNames = [
        'Orderid',
        'Customername',
        'Price',
        'Quantity',
        'Productname',
    'Total Including Tax',
    'Email',
    'Town',
    'Country', 'Postcode', 'Homephone','Workphone','Deliveryname','Deliverytown','Deliveryphone','Deliverypostalcode','Shippingmethod'];
    var colModel = [
        { name: 'Orderid', index: 'Orderid', align: 'left',  width: 20 },
        { name: 'Customername', index: 'Customername', edittype: 'image', align: 'left', width: 70, },
        { name: 'Price', index: 'Price', align: 'left', width: 100,  },
        { name: 'Quantity', index: 'Quantity', align: 'left', width: 150, },
        { name: 'Productname', index: 'Productname', align: 'left', width: 150 },
        { name: 'Totalincludingtax', index: 'Totalincludingtax', align: 'left', width: 150 },
        { name: 'Email', index: 'Email', align: 'left', width: 100, },
         { name: 'Town', index: 'Town', align: 'left', width: 100 },
         { name: 'Country', index: 'Country', align: 'left', width: 100,  },
          { name: 'Postcode', index: 'Postcode',  align: 'left', width: 70 },
           { name: 'Homephone', index: 'Homephone',  align: 'left', width: 70 },
         { name: 'Workphone', index: 'Workphone',  align: 'left', width: 70 },

         { name: 'Deliveryname', index: 'Deliveryname',  align: 'left', width: 70 },
         { name: 'Deliverytown', index: 'Deliverytown',  align: 'left', width: 70 },
         { name: 'Deliveryphone', index: 'Deliveryphone',  align: 'left', width: 70 },
         { name: 'Deliverypostalcode', index: 'Deliverypostalcode', align: 'left',             width: 70 },
         { name: 'Shippingmethod', index: 'Shippingmethod',  align: 'left', width: 70 }
    ];
    var sortname = 'Orderid';
    var sortorder = 'desc';
    SetGrid('#jqgprojectnew', '', url, colNames, colModel, sortname, sortorder, -1);




});
</script>

在网页视图中它是如何加载的

 <script type="text/javascript"> $(document).ready(function () {
  $("a.button").button();
   var url = '';
    var colNames = [
   'Orderid',
    'Customername',
   'Price',
    'Quantity',
      'Productname',
    'Total Including Tax',
     'Email',
      'Town',
       'Country', 'Postcode',                            'Homephone','Workphone','Deliveryname','Deliverytown','Deliveryphone','Deliverypostalcode','Shippingmethod'];

设置网格的代码:

function SetGrid(v_gridCtrl,v_pagingCtrl, v_url, v_colNames, v_colModel, v_sortname, v_sortorder, v_Pagesize) {

if (v_Pagesize == undefined)
    v_Pagesize = 100;

$(v_gridCtrl).jqGrid({
    //url from wich data should be requested
    autowidth: true,
    url: v_url,
    //type of data
    datatype: 'json',
    //url access method type
    mtype: 'POST',
    //columns names
    colNames: v_colNames,
    //columns model
    colModel: v_colModel,
    //pager for grid
    pager: $(v_pagingCtrl),
    //enable dynamic scrolling
    //scroll: true,
    //enable npage request parameter
    prmNames: { npage: 'npage' },
    //number of rows per page
    rowNum: v_Pagesize,
    rowList: [10, 30, 60, 90, 100, 150, -1],
    loadComplete: function () {
        $("option[value=-1]").text('All');
        $('#count').html($(v_gridCtrl).getGridParam("reccount"));
    },

    //initial sorting column
    sortname: v_sortname,
    //initial sorting direction
    sortorder: v_sortorder,
    //we want to display total records count
    viewrecords: true,
    //grid height
    height: 400,//'100%',
    width: '100%',
    scrollOffset: 0,
    shrinkToFit: true
});

}

我的问题是: jqgrid 中使用的操作方法没有命中,加载时 url 操作结果为空

4

1 回答 1

0
  • 在脚本中添加 document.ready()
  • 像这样设置网址:

    var url = '/ControllerName/Listmanoj'; //如果你的控制器名称是TestController,url应该是'/Test/Listmanoj'

  • 删除以下部分:(你为什么需要那个?)

    $(document).ready(function () { $("a.button").button(); var url = ''; var colNames = [ 'Orderid', 'Customername', 'Price', 'Quantity', 'Productname', 'Total Include Tax', 'Email', 'Town', 'Country', 'Postcode', 'Homephone','Workphone','Deliveryname','Deliverytown','Deliveryphone','Deliverypostalcode', '邮寄方式'];

  • 在 document.ready() 中包含 setGrid。

简而言之,您的脚本部分应如下所示:

    <asp:Content ID="Content3" ContentPlaceHolderID="MetaContent" runat="server">
    <table  id="jqgprojectnew" style="width: 100%">
      </table>
     <script type="text/javascript"> 

$(document).ready(function()
{
//set grid function

function SetGrid(v_gridCtrl,v_pagingCtrl, v_url, v_colNames, v_colModel, v_sortname, v_sortorder, v_Pagesize) {

if (v_Pagesize == undefined)
    v_Pagesize = 100;

$(v_gridCtrl).jqGrid({
    //url from wich data should be requested
    autowidth: true,
    url: v_url,
    //type of data
    datatype: 'json',
    //url access method type
    mtype: 'POST',
    //columns names
    colNames: v_colNames,
    //columns model
    colModel: v_colModel,
    //pager for grid
    pager: $(v_pagingCtrl),
    //enable dynamic scrolling
    //scroll: true,
    //enable npage request parameter
    prmNames: { npage: 'npage' },
    //number of rows per page
    rowNum: v_Pagesize,
    rowList: [10, 30, 60, 90, 100, 150, -1],
    loadComplete: function () {
        $("option[value=-1]").text('All');
        $('#count').html($(v_gridCtrl).getGridParam("reccount"));
    },

    //initial sorting column
    sortname: v_sortname,
    //initial sorting direction
    sortorder: v_sortorder,
    //we want to display total records count
    viewrecords: true,
    //grid height
    height: 400,//'100%',
    width: '100%',
    scrollOffset: 0,
    shrinkToFit: true
});
}// end of set grid function

    var url = 'controllername/Listmanoj';
        var colNames = [
            'Orderid',
            'Customername',
            'Price',
            'Quantity',
            'Productname',
        'Total Including Tax',
        'Email',
        'Town',
        'Country', 'Postcode', 'Homephone','Workphone','Deliveryname','Deliverytown','Deliveryphone','Deliverypostalcode','Shippingmethod'];
        var colModel = [
            { name: 'Orderid', index: 'Orderid', align: 'left',  width: 20 },
            { name: 'Customername', index: 'Customername', edittype: 'image', align: 'left', width: 70, },
            { name: 'Price', index: 'Price', align: 'left', width: 100,  },
            { name: 'Quantity', index: 'Quantity', align: 'left', width: 150, },
            { name: 'Productname', index: 'Productname', align: 'left', width: 150 },
            { name: 'Totalincludingtax', index: 'Totalincludingtax', align: 'left', width: 150 },
            { name: 'Email', index: 'Email', align: 'left', width: 100, },
             { name: 'Town', index: 'Town', align: 'left', width: 100 },
             { name: 'Country', index: 'Country', align: 'left', width: 100,  },
              { name: 'Postcode', index: 'Postcode',  align: 'left', width: 70 },
               { name: 'Homephone', index: 'Homephone',  align: 'left', width: 70 },
             { name: 'Workphone', index: 'Workphone',  align: 'left', width: 70 },

             { name: 'Deliveryname', index: 'Deliveryname',  align: 'left', width: 70 },
             { name: 'Deliverytown', index: 'Deliverytown',  align: 'left', width: 70 },
             { name: 'Deliveryphone', index: 'Deliveryphone',  align: 'left', width: 70 },
             { name: 'Deliverypostalcode', index: 'Deliverypostalcode', align: 'left',             width: 70 },
             { name: 'Shippingmethod', index: 'Shippingmethod',  align: 'left', width: 70 }
        ];
        var sortname = 'Orderid';
        var sortorder = 'desc';
        SetGrid('#jqgprojectnew', '', url, colNames, colModel, sortname, sortorder, -1);




    });
    </script>
于 2013-04-02T09:07:35.993 回答