0

I am confused about the guide lines for dealing with ajax post requests in MVC2 How do i know what data the grid is passing as request parameters? in what order and what data type? because after knowing this only one can design the server side post method. I have seen many example with different function prototypes as server side method handler.

How is that possible? i mean it is the same jqgrid which doing ajax post. How can there be different types of function prototypes as server side action for the same jqgrid?

EDIT

My requirement is i want to send some extra data like a dropdown list selected value when ever JqGrid does an ajax call. But MVC does accept only the JqGrid parameters. I have a workaround though i add extra data through "paramData" and i am able to receive it in the controller request handler. The problem is we use a Grid class which deserializes the Grid parameters and this class is global to the app. so modifying it for each page is a no.

what i need is this which does not work only the 1st parameter is populated:-

public void Jgrid(Jgrid grid,object hdnupdpg,string p_roleid)
{
}

but how do i make Jgrid.ajax call send these otherparams ? with "paramsData" option only?

here is the server side function prototypes i came across :

public void JGridData(JGrid grid)
{

}

And here is the grid class

    public class JGrid
    {
        private bool IsSearch;
        public string sidx { get; set; }
        public string sord { get; set; }
        public int page { get; set; }
        public int rows { get; set; }

        public bool _search
        {
            get
            {
                string strSearch = HttpContext.Current.Request["_search"];
                if (!string.IsNullOrEmpty(strSearch))
                    return Convert.ToBoolean(strSearch);
                else
                    return IsSearch;
            }
            set { IsSearch = value; }
        }

        public string searchOper { get; set; }
        public string filters { get; set; }
        public int totalRecords { get; set; }
        public string procName { get; set; }
        public string SearchValue { get; set; }
        public string SearchField { get; set; }

        public string defaultFilter { get; set; }

        public string SortExpression
        {
            get { return sidx + " " + sord; }
        }


        public string FilterExpression
        {
            get
            {
                string filter = BuildFilter();
                if (!string.IsNullOrEmpty(defaultFilter) && !string.IsNullOrEmpty(filter))
                    return defaultFilter
                           + " AND (" + filter + ")";
                else if (!string.IsNullOrEmpty(defaultFilter))
                    return defaultFilter;
                return filter;
            }
        }

        public string BuildFilter()
        {
         ....
        }
}

EDIT

Here is my Script for JqGrid

    jQuery('#jgrid').jqGrid({
        autowidth: true,
        altRows: true,
        altclass: 'grdAltRwClr',
        datatype: 'local',
        forceFit: true,
        gridview: true,
        height: 290,
        mtype: 'post',
        rowList: [10, 20, 30],
        rowNum: 10,
        pager: '#pager',
        pagerpos: 'right',
        recordpos: 'left',
        rownumbers: false,
        scrollrows: false,
        sortname: 'roledtlid',
        toolbar: [true, "top"],
        url: rootPath + 'RoleDetail/JGridData',
        postData: { extraparams: function() { return escape(jQuery('#hdnupdpg').val()); },
        parentid: function() { return escape(jQuery('#p_roleid').val()); }
         },
        beforeSelectRow: function(rowid, e) { return false; },
        gridComplete: function() { GridComplete() },
        colModel: [
              { name: 'act', label: 'View', resizable: false, search: false, sortable: false, title: false, width: 6, index: 'act' }
            , { name: 'roleid', label: 'Role id', width: 10, index: 'roleid' }
            , { name: 'rolename', label: 'Role Name', width: 25, index: 'rolename' }
            , { name: 'pgname', label: 'Page Name', width: 30, index: 'pgname' }
            , { name: 'canedit', label: 'Edit', width: 10, index: 'canedit' }
            , { name: 'canview', label: 'View', width: 10, index: 'canview' }
             ]
    });
tereško
  • 58,060
  • 25
  • 98
  • 150
Deb
  • 981
  • 13
  • 39

2 Answers2

3

The list of parameters which will be send to the server depend on the options which you use. You don't posted javaScript code which you use. The names of any parameters you can redefine with respect of prmNames option of jqGrid. The following parameters will be always send to the URL used for filling the grid

  • page - the the requested page - default value page,
  • rows - the number of rows requested - default value rows,
  • sort - the sorting column - default value sidx,
  • order - the sort order default value sord,
  • search - the search indicator - default value _search

If you use Advanced Searching dialog or filter toolber with parameter stringResult: true the information about the filter will be sent in additional parameter filters in the format described here.

For example if you set Cache-Control: private, max-age=0 in the header of the server response (see here or here) or control the caching with other Cache-Control parameters of the server response you can remove nd parameter which contains the timestamp:

prmNames: { nd: null }

If you want rename _search parameter to isSearch for example you can use

prmNames: { search: 'isSearch' }

You can of cause combine all settings which you need:

prmNames: { nd: null, search: 'isSearch' }
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • So if i have to send an extra custom parameter through paramsdata will i have to change my grid class ? Is there any way i can use two or more parameters in my MVC post handler for the JqGrid ajax request? and if so how do i configure grid's ajax call to send those extra parameters? I cant keep on changing my Grid class for each page. – Deb Apr 11 '12 at 12:20
  • @Deb: Sorry, but I don't understand how you want to use the "extra custom parameter" on the server side. So it's difficult to comment the definition of the Grid class which you use. Do you tried just use `public void JGridData(JGrid grid, string extraparams, string parentid)`? By the way the usage of `escape` function inside of `postData` is not needed. The data will be send by `$.ajax` which call internally `$.param` which uses [encodeURIComponent](http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp). – Oleg Apr 11 '12 at 22:31
  • Suppose i want to populate the grid based on some dropdown list value which is a parameter to my stored procedure, in that case i need to send regular JQuery Grid parameters plus the drop down list selected value. For common Jgrid parameters i am using the Jgrid Class but for the dropdown value i have no control on the ajax call the jqGrid is invoking. I can edit my JGrid class but it is used in every controller so cant modify it for each page. This is the dialema.... – Deb Apr 12 '12 at 05:25
  • @Deb: First of all you should append your question with additional information instead of modifying the full text or the code. You should think about other reader of the question. If somebody will read my question now it will be many things unclear. Now to your problem. I don't understand it really. In any way it's not a jqGrid problem. jqGrid can send and parameters which you need, like the value from `#hdnupdpg` and `#p_roleid` controls. On the server side you have to use **the same names of parameters**. If you use `extraparams` for `#hdnupdpg` and `parentid` for `#p_roleid` you should ... – Oleg Apr 12 '12 at 10:11
  • @Deb: You should use `public void Jgrid(Jgrid grid, string extraparams, string parentid)` instead of `public void JGridData (Jgrid grid,object hdnupdpg,string p_roleid)`. You can additionally use prototype like `public void JGridData (int page, int rows, string sidx, string sord, bool _search, string extraparams, string parentid)` and use `Jgrid` constructor inside of `JGridData` body. – Oleg Apr 12 '12 at 10:12
2

It is not clear which method of jqgrid are you interested in. But let me try

In general - request parameter you are interested in can be seen using Firebug for Firefox

  • Install Firebug add-on in your Firefox
  • Open the page with the jqgrid/or open the jqgrid demo page if you don't have one already
  • Activate the Firebug console from the top right corner of your Firefox
  • Watch the request response in the Net tab in Firebug
  • If you expand the request it will show All Parameters and Header information being sent in that particular request
t0s6i
  • 161
  • 3