在ASP.NET MVC 3.0應用程序中,我使用jqGrid。我使用下面的代碼。我看到網格,但沒有數據。我通過了「GridData」操作,列表內容是一個元素,但網格中沒有任何內容。jqGrid沒有數據顯示在網格中
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>
我試過你的代碼一些結果...網格中沒有數據 –
你應該使用調試器,然後獲得更多關於你的問題的信息 – Zruty
你認爲我不使用調試器? :)在返回的調試點中,列表有1個元素。我無法告訴你更多。 –