Shekar.gvr Shekar.gvr - 22 days ago 6
Javascript Question

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

I have a Jquery grid which i am binding using an ajax call to the controller.
The controller method is being hit during the ajax call, but the parameter values as passing as null tothe controller method.

The parametre values are bound correctly in the ajax property

'data:'


Here is my JavaScript Code:

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");
}

}


Here is my controller method

public string GetGeographyBreakUpData(string BUIds, string ZoneIds, string RegionIds, string TerritoryIds, string MarketIds, string FOIds, string ResponseTypeIds, string FromDate, string ToDate, string GridBreakUpLevel)
{
}


Can someone tell me where my code is at fault?

UPDATE
I have tried to send the values using the
Params
array,
even then the
Params
array is passed as
null


Here is the updated code

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)
{
}


Even this doesn't work.

Answer

In the best of my knowledge the data property fails to form as query string parameters due to the datatype: json. Not because it's incorrect, but it probably transformed it for content-type "application/x-www-form-urlencoded"

I suspect processData property is probably the cause for failing. I haven't tried it practically to support this, I'm open for people to edit this answer if they find otherwise.

As for the question we are setting the parameters in traditional way

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

If I find anything more i will update on this.Just wanted to share this jQuery.param() too