In an ASP.NET MVC 3.0 application, I use jqGrid. I use the code below. I see the grid but no data in. I passed in the "GridData" action, the list content is one element but nothing in the grid.
C# :
public ActionResult GridData()
{
List<Customer> list = new List<Customer>();
list.Add(new Customer() { Code = "AAA", FirstName = "BBB", LastName = "CCC" });
return Json(list);
}
HTML :
<table id="jqgProducts" cellpadding="0" cellspacing="0"></table>
<div id="jqgpProducts" style="text-align:center;"></div>
<script type="text/javascript">
$(document).ready(function () {
$('#jqgProducts').jqGrid({
//url from wich data should be requested
url: '/Customer/GridData/',
//type of data
datatype: 'json',
//url access method type
mtype: 'GET',
//columns names
colNames: ['Id', 'LastName','FirstName', 'Code'],
//columns model
colModel: [
{ name: 'Id', index: 'Id', align: 'left' },
{ name: 'LastName', index: 'LastName', align: 'left' },
{ name: 'FirstName', index: 'FirstName', align: 'left' },
{ name: 'Code', index: 'Code', align: 'left' }
],
//pager for grid
pager: $('#jqgpProducts'),
//number of rows per page
rowNum: 10,
//initial sorting column
sortname: 'Id',
//initial sorting direction
sortorder: 'asc',
//we want to display total records count
viewrecords: true
});
});
</script>