c# - jqGrid is loading JSON but not displaying it -


i have been reading wide variety of posts , documentation issue, , have tried have read , can think of - still stumped.

i'm trying load json data server jqgrid in dot net nuke website. using dnn not choice, there no option not use it. being said, i've set standard dnn website , added c# class library project (named apilibrary) it. in it, there 2 classes:

routemapper.cs

using dotnetnuke.web.api;  namespace apilibrary {     public class routemapper : iserviceroutemapper     {         public void registerroutes(imaproute maproutemanager)         {             maproutemanager.maphttproute("apilibrary", "default", "{controller}/{action}", new[] { "apilibrary" });                   }     } } 

and welcomecontroller.cs contains ajax functions. 1 using jqgrid following:

[webinvoke(method = "post", responseformat = webmessageformat.json, requestformat = webmessageformat.json)] public string getmydata(string sidx, string sord, int page, int rows)         {             var mylist = gettransporttable(); // returns list<transportinfo>             var rowlist = new list<row>() { };             int m = 0;             (var = 0; < mylist.count; i++)             {                 m = + 1;                 row rowobj = new row();                 var stringlist = new list<string>();                 rowobj.id = m.tostring();                  stringlist.add(mylist[i].pilot);                 stringlist.add(mylist[i].vessel);                 stringlist.add(mylist[i].dock);                 stringlist.add(mylist[i].amount.tostring("c"));                  rowobj.cell = stringlist;                 rowlist.add(rowobj);             }              var jsontoreturn = new             {                 total = 3,                 page = 1,                 records = mylist.count.tostring(),                 rows = rowlist.toarray()             };               string jdata = string.empty;                     jdata = jsonconvert.serializeobject(jsontoreturn);              return jdata;         } 

this returns 100% valid json (verified on jslint) in format jqgrid wants - i.e:

{ "total": "4", "page": "1", "records": "4", "rows" : [ { "id": "1", "cell":["myname", "myboat", "mydock", "144"] }, { "id": "2", "cell":["myname1", "myboat1", "mydock1", "1414"] } ] }

for each event listed in jqgrid documentation if alert() display data during event displays formatted json. telling me jqgrid receiving data fine, blocking displaying data.

i've tried using jsonreader, jsonmap, , pretty every other suggestion/option i've come across.

i have checked , doublechecked javascript , css references , go. here javascript loading grid:

$("#reviewlist").jqgrid({  ajaxgridoptions: { contenttype: 'application/json; charset=utf-8' }, url: 'desktopmodules/apilibrary/api/welcome/getmydata', jsonreader: {                 repeatitems: false,                 id: "id",                 root: "rows",                 page: "page",                 total: "total",                 records: "records",                 cell: "cell"             }, colnames: ['pilot', 'vessel', 'dock', 'amount'], colmodel: [  { name: 'pilot', width: 250, align: 'center' },  { name: 'vessel', width: 250, align: 'center' },  { name: 'dock', width: 175, align: 'center' },  { name: 'amount', width: 110, align: 'center' } ], rownum: 10, rowlist: [10, 20, 30], pager: "#pager2", viewrecords: true, sortname: 'pilot', sortorder: 'asc', caption: 'transport list overview'   }).navgrid("#pager2", { edit: false, add: false, del: false }); 

it's worth noting have used several other ajax calls jquery (both , post) on same page , have had no issues parsing json. also, json (from jquery ajax calls outside of jqgrid) can display in jqgrid. however, since local data, can't sort/page/search - that's no me.

what going wrong?

i looked bit deeper dnn services framework, , able working modifying ajax method in welcomcontroller.cs following:

    [system.web.http.httppost]     public httpresponsemessage getmydata()     {         var mylist = gettransporttable(); //returns list<transportinfo>         var rowlist = new list<row>() { };          (var = 0; < mylist.count; i++)         {             row rowobj = new row();             var stringlist = new list<string>();             rowobj.id = i;              stringlist.add(mylist[i].dockdate.tostring("d"));             stringlist.add(mylist[i].pilot);             stringlist.add(mylist[i].vessel);             stringlist.add(mylist[i].dock);             stringlist.add(mylist[i].amount.tostring("c"));              rowobj.cell = stringlist;             rowlist.add(rowobj);         }          var jsontoreturn = new         {             total = 1,             page = 1,             records = mylist.count.tostring(),             rows = rowlist         };          return request.createresponse(httpstatuscode.ok, jsontoreturn);     } 

and in javascript removed jsonreader , added mtype:'post'. new jqgrid function is:

$("#reviewlist").jqgrid({             loaderror: function(xhr, status, error) {                 alert('load error: ' + error);             },                 mtype: 'post',             ajaxgridoptions: { contenttype: 'application/json; charset=utf-8' },             url: 'desktopmodules/apilibrary/api/welcome/getmydata',             datatype: "json",              colnames: ['date','pilot', 'vessel', 'dock', 'amount'],             colmodel: [                 {name: 'dockdate', index:'dockdate', width: 90,  align: 'center'},                                 { name: 'pilot', index: 'pilot', width: 250, sortable: true, align: 'center' },                 { name: 'vessel', index: 'vessel', width: 250, sortable: true, align: 'center' },                 { name: 'dock', index: 'dock', width: 175, sortable: true, align: 'center' },                 { name: 'amount', index: 'amount', width: 110, sortable: true, align: 'center', sorttype: 'float' }             ],              rownumbers: true,             rownum: 10,             rowlist: [10, 20, 30],             pager: "#pager2",             viewrecords: true,             caption: 'transport list overview',             height: "auto"             //loadonce: true         }).navgrid("#pager2", { edit: false, add: false, del: false }); 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -