我有一个 Jquery 网格,我使用对 Controller 的 ajax 调用来绑定(bind)它。 Controller 方法在 ajax 调用期间被命中,但参数值作为 null 传递给 Controller 方法。
参数值在 ajax 属性 'data:'
中正确绑定(bind)
这是我的 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");
}
}
这是我的 Controller 方法
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});
Controller
public string GetGeographyBreakUpData(string Parameters)
{
}
即使这样也行不通。
最佳答案
据我所知,由于 datatype: json
,data
属性无法形成查询字符串参数。不是因为它不正确,而是它可能将其转换为 content-type "application/x-www-form-urlencoded"
我怀疑processData属性(property)可能是失败的原因。我还没有实际尝试过支持这一点,如果人们发现其他情况,我愿意让他们编辑这个答案。
关于我们传统方式设置参数的问题
url: "@Url.Action("GetGeographyBreakUpData", "GeoMap")"+"?BUIds='"+ BUids + "'&ZoneIds='"+Zoneids+"'&RegionIds='"+Regionsids+"'&TerritoryIds='"+Territoryids+"'"
如果我发现更多我会更新这个。只是想分享这个 jQuery.param()也是
关于javascript - 使用 Jquery Grid ajax 调用绑定(bind)网格数据时参数传递为 'null',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40647048/