In my application, I will fetch a table of data from the server side when the page is first loaded, and use jqgrid to render it.
I can't seem to get it to work, when I request for the DummyView
page for the example below, the web browser pops up a message, asking me to download the application/json
file, indicates that something is deeply wrong. Here's my Jquery code:
$(document).ready(function(){
$("#list4").jqGrid({
url:'../../ViewRecord/DummyView',
datatype:'JSON',
mtype: 'GET',
colNames:['Id','Name','Description'],
colModel:[
{name:'id',index:'id',width:55,resizable:true},
{name:'name',index:'name',width:90,resizable:true},
{name:'description',index:'description',width:120,resizable:true}],
pager: jQuery('#pager'),
rowNum:10,
rowList:[5,10,20,50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
imgpath:'/images',
caption: 'My first grid'
});
});
And here's my ViewRecord/DummyView
controller method:
public ActionResult DummyView()
{
var page = new { page = 1 };
var rows = new object[2];
rows[0] = new { id = 222, cell = new[] { "222", "Blue", "This is blue" } };
rows[1] = new { id = 2, cell = new[] { "2", "Red", "This is red" } };
//var endarray = new[] {page, rows};
var result = new JsonResult();
result.Data = new { page = 1, records = 2, rows, total = 1 };
return result;
}
Any idea how to get jqgrid to work with ASP.NET MVC?