I've used jqGrid for long time now, without any kind of proble开发者_C百科m. Today I've tried to implement it in ASP.NET MVC 2 project and things didn't work as expected.
After a little struggle I've realized that now controllers do not accept GET calls when returning JSON data. It is for security reasons. If I force my controller to support GET - forcing the JSON response like this:return(Json(value, JsonRequestBehavior.AllowGet))
... and specifying
[AcceptVerbs( HttpVerbs.Get )]
on the method
everything works fine and my jqGrid shows the results. I've tried to change the verb of the jqGrid myType: 'POST' but the grid stops working.
I've done a little bit of debugging and tracing and it seems that jqGrid never POSTs the request. My controller always receives a GET.Is there anybody who can help me, please.
Thanks
Alberto
SAMPLE:
jQuery("#ProvincesDynamicGrid").jqGrid({
url: '<%=Url.Action("Fetch", "Provinces")%>',
postData: { id: '0' },
datatype: 'json',
myType: 'POST',
colNames: ['Descr', 'Prov', 'Regione'],
colModel: [{ name: 'Description', index: 'Description', editable: false, resizable: true, sortable: false, width: 200, align: 'right' },
{ name: 'Initial', index: 'Initial', editable: true, editrules: { required: true, custom: true, custom_func: ValidateInitialColum }, resizable: true, sortable: false, width: 90, align: 'right' },
{ name: 'RegionDescription', index: 'RegionDescription', editable: false, resizable: true, sortable: false, width: 200, align: 'right' }
],
pager: $('#ProvincesDynamicPager'),
rowNum: 11,
// rowList: [10, 20, 50],
width: 748,
height: 253,
viewrecords: true,
shrinkToFit: false,
scroll: false,
rownumbers: true,
hidegrid: false,
caption: 'Gestione Province',
cellEdit: true,
cellsubmit: 'remote',
cellurl: '<%=Url.Action("SaveProvince", "Provinces")%>',
onSelectRow: function(id) {
SelectedRowId = id;
},
beforeSaveCell: function(rowid, cellname, value, iRow, iCol) {
},
afterSubmitCell: function(serverresponse, rowid, cellname, value, iRow, iCol) {
var resp = jQuery.parseJSON(serverresponse.responseText);
// if (resp.Status == false)
return ([resp.Status, resp.Message])
//alert(resp.Message);
}
});
As Tony suggested in the jqGrid forum I was mispelling the mtype parameter (myType: 'POST') So the exact code would be like this:
jQuery("#ProvincesDynamicGrid").jqGrid({
url: '<%=Url.Action("Fetch", "Provinces")%>',
postData: { id: '0' },
datatype: 'json',
mtype: 'POST',
colNames: ['Descr', 'Prov', 'Regione'],
colModel: [{ name: 'Description', index: 'Description', editable: false, resizable: true, sortable: false, width: 200, align: 'right' },
{ name: 'Initial', index: 'Initial', editable: true, editrules: { required: true, custom: true, custom_func: ValidateInitialColum }, resizable: true, sortable: false, width: 90, align: 'right' },
{ name: 'RegionDescription', index: 'RegionDescription', editable: false, resizable: true, sortable: false, width: 200, align: 'right' }
],
pager: $('#ProvincesDynamicPager'),
rowNum: 11,
...
Now everything works fine.
精彩评论