3

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.

WorksOnMyLocal
  • 1,617
  • 3
  • 23
  • 44
  • Im not sure `data` property is used here by the grid. Are you able to build the url with the search parameters and try? – Searching Nov 17 '16 at 05:21
  • @Searching Then how do i pass the parametres without the data property? – WorksOnMyLocal Nov 17 '16 at 05:24
  • ah yup try this quick and dirty check to see if the parameters is being passed, `"@Url.Action("GetGeographyBreakUpData", "GeoMap")" + "?BUIds='" + BUids + "'"` . are you able to share `ActionResult GetGeographyBreakUpData(...)` ? just the method signature.. – Searching Nov 17 '16 at 05:57
  • Yes i will share the method signature, refer the question above i have updated accordingly. – WorksOnMyLocal Nov 17 '16 at 06:00
  • Oh nice.. Just wanted to see if the parameters type.. Let me know how the check goes.. only buids will be passed others will be `null` for this test. – Searching Nov 17 '16 at 06:03
  • `"@Url.Action("GetGeographyBreakUpData", "GeoMap")" + "?Parameters='" + Params + "'"` – Searching Nov 17 '16 at 06:08
  • @Searching ok, i will try this check. In the mean while please check my updated code in which i am trying to send Params array as data property instead of individual parametres. Even this doesn't work, your comment on this? – WorksOnMyLocal Nov 17 '16 at 06:08
  • try to avoid that. It's probably for `POST` action. For `GET` try sending the way suggested and see if it comes through. Just confirming it does touch the `Action` correct ? – Searching Nov 17 '16 at 06:09
  • @Searching Yes it does hit the action, and yes the BUIds are passing correctly now. – WorksOnMyLocal Nov 17 '16 at 06:13
  • Great sorted or should I post it as answer..? – Searching Nov 17 '16 at 06:14
  • @Searching yes post it, it might be helpful for others. But can you explain why this is happening?why cant it take the values from data property? – WorksOnMyLocal Nov 17 '16 at 06:15
  • @Searching hey, can you help me in one more issue which is related to Bootstrap-Multiselect dropdown? – WorksOnMyLocal Nov 17 '16 at 06:52
  • I can try. Is that already a question on SO? I'll be off for a bit. It's already night time here. Don't expect instant answer :) – Searching Nov 17 '16 at 06:56
  • @Searching yes no problem, take your time. But here is the link to the SO question of mine. http://stackoverflow.com/questions/40648410/bootstrap-multiselect-dropdown-change-event-on-cascading-dropdowns. – WorksOnMyLocal Nov 17 '16 at 07:00

1 Answers1

1

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

Searching
  • 2,269
  • 1
  • 17
  • 28