参数以'null'使用Jquery时调用ajax绑定网格数据

Parametres passing as 'null' when using Jquery Grid ajax call for binding grid data

本文关键字:ajax 绑定 网格 数据 调用 使用 null 参数 Jquery      更新时间:2023-09-26

我有一个Jquery网格,我使用ajax调用绑定到控制器。在ajax调用期间,控制器方法被击中,但是参数值作为null传递给控制器方法。

在ajax属性'data:'

中正确绑定了参数值

这是我的JavaScript代码:

function BindGridData()
    {

        var BUids=$("#ddlBU").val().join(",");
        var Zoneids=$("#ddlZone").val().join(",");
        var Regionsids=$("#ddlRegion").val().join(",");
        var Territoryids=$("#ddlTerritory").val().join(",");
        $("#tblJQGrid").jqGrid(
        {url: "@Url.Action("GetGeographyBreakUpData", "GeoMap")",
            datatype: "json",
            data: "{BUIds :'" + BUids + "',ZoneIds:'"+Zoneids+"',RegionIds:'"+Regionsids+"',TerritoryIds:'"+Territoryids+"'}",
            mtype: 'GET',
            colNames: ['Id','GeoGraphy', 'Completed', 'InProgress'],
            colModel: [
            { name: 'Id', index: 'Id', width: 20, stype: 'text',hidden:true },
            { name: 'Geography', index: 'Geography', width: 150 },
            { name: 'Completed', index: 'Completed', width: 150 },
            { name: 'InProgress', index: 'InProgress', width: 150 },
            ],rowNum: 10,
            sortname: 'Id',
            viewrecords: true,
            sortorder: "desc",
            caption: "Geographical Survey Status",
            scrollOffset: 0});
        var res=$('#ddlResponseType').val();
        res=res.join(',');
        if(res=='1')
        {
            $("#tblJQGrid").hideCol("Completed");
        }
        else if(res == '2')
        {
            $("#tblJQGrid").hideCol("InProgress");
        }
        else
        {
            $("#tblJQGrid").showCol("InProgress");
            $("#tblJQGrid").showCol("Completed");
        }
    }
这是我的控制器方法
public string GetGeographyBreakUpData(string BUIds, string ZoneIds, string RegionIds, string TerritoryIds, string MarketIds, string FOIds, string ResponseTypeIds, string FromDate, string ToDate, string GridBreakUpLevel)
{
}

谁能告诉我我的代码错在哪里?

我试图使用Params数组发送值,即使这样,Params数组也作为null

传递。

下面是更新后的代码

var BUids=$("#ddlBU").val();
var Zoneids=$("#ddlZone").val();
var Regionsids=$("#ddlRegion").val();
var Territoryids=$("#ddlTerritory").val();
Params = new Array();
Params.push(BUids);
Params.push(Zoneids);
Params.push(Regionsids);
Params.push(Territoryids);
Params = Params.join("|");
$("#tblJQGrid").jqGrid(
    {url: "@Url.Action("GetGeographyBreakUpData", "GeoMap")",
        datatype: "json",
        data: { "Parameters": Params },
        mtype: 'GET',
        colNames: ['Id','GeoGraphy', 'Completed', 'InProgress'],
        colModel: [
        { name: 'Id', index: 'Id', width: 20, stype: 'text',hidden:true },
        { name: 'Geography', index: 'Geography', width: 150 },
        { name: 'Completed', index: 'Completed', width: 150 },
        { name: 'InProgress', index: 'InProgress', width: 150 },
        ],rowNum: 10,
        sortname: 'Id',
        viewrecords: true,
        sortorder: "desc",
        caption: "Geographical Survey Status",
        scrollOffset: 0});
控制器

public string GetGeographyBreakUpData(string Parameters)
{
}

据我所知,由于datatype: json, data属性无法形成查询字符串参数。不是因为它是不正确的,但它可能转换为content-type "application/x-www-form-urlencoded"

我怀疑processData属性可能是失败的原因。我还没有尝试过实际支持这个问题,我愿意让人们编辑这个答案,如果他们发现其他的。

对于这个问题,我们用传统的方式设置参数

url: "@Url.Action("GetGeographyBreakUpData", "GeoMap")"+"?BUIds='"+ BUids + "'&ZoneIds='"+Zoneids+"'&RegionIds='"+Regionsids+"'&TerritoryIds='"+Territoryids+"'"

如果我发现更多的我会更新这个。只是想分享这个jQuery.param()