I'm using jqgrid in my MVC3 application to bind the data in Razor view(.cshtml). The values are sent from the controller as JSON. But its not binding.
//Controller:
public JsonResult LoadData()
{
Connect objMC = new Connect();//Helper Class
var collectionEmployee = objMC.LoadAllData();//Gets Employee Collection
var jsonSerializer = new JavaScriptSerializer();
return Json(jsonSerializer.Serialize(collectionEmployee.AsQueryable<Product>().ToList<Product>()));
}
//jqGrid:
jQuery("#jQGridDemo").jqGrid({
url: '@(Url.Action("LoadData", "Home"))',
datatype: "json",
mtype: 'GET',
colNames: ['ProductId', 'Name', 'AdminContent', 'ProductTemplate', 'CreatedOnUtc'],
colModel: [{ name: 'ProductId', index: 'ProductId', width: 200, align: 'left', sorttype: 'int' },
{ name: 'Name', index: 'Name', width: 200, align: 'left', sortable: true, editable: true },
{ name: 'AdminContent', index: 'AdminContent', width: 200, align: 'left', sortable: true, editable: true },
{ name: 'ProductTemplate', index: 'ProductTemplate', width: 200, editable: true, edittype: "select", editoptions: { value: "1:VariantsInGrid;2:SingleProductVariant;3:MultipleProducts" }, align: 'left' },
{ name: 'CreatedOnUtc', index: 'CreatedOnUtc', width: 200, align: 'left', edittype: 'text', formatter: 'date', formatoptions: { newformat: 'm-d-Y' }, datefmt: 'm-d-Y',
editoptions: {
size: 10, maxlengh: 10,
dataInit: function (element) {
$(element).datepicker({ dateFormat: 'yy.mm.dd' })
}
}, sortable: true, editable: true
}
],
rowNum: 10,
rowList: [10, 20, 30],
pager: '#jQGridDemoPager',
sortname: '_id',
viewrecords: true,
sortorder: 'desc',
caption: "Grid",
ignoreCase: true
});
jQuery("#jQGridDemo").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn" });
//HTML:
<h2>
New Grid</h2>
<table id="jQGridDemo">
</table>
The controller is getting called and the values are passed from the controller to view. But the values are not getting bind. Just i'm seeing an empty grid. This works perfect when i'm using a handler(.ashx) to load the grid.
Where i'm wrong?