Reputation: 991
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' }
]
});
Upvotes: 0
Views: 3467
Reputation: 221997
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
, rows
, sidx
, sord
, _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' }
Upvotes: 3
Reputation: 171
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
Upvotes: 2