this is my controller
public JsonResult gridview()
{
var jsonData = new {
total = 1,
page = 1,
records = db.TestModels.Count(),
rows = (
from question in db.TestModels.AsEnumerable()
select new {
id = question.Dataid,
cell = new string[3] {
question.Dataid.ToString(), question.Name, question.Emailid
}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
}
}
this is my view
<link rel="stylesheet" type="text/css" href="~/jqgrid/css/ui.jqgrid.css"
title="coffee" media="screen" />
<script src="~/Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<script src="~/jqgrid/src/jquery.jqGrid.js" type="text/javascript"></script>
<script src="~/jqgrid/src/jqModal.js" type="text/javascript"></script>
<script src="~/jqgrid/src/jqDnR.js" type="text/javascript"></script>
<table id="list" class="scroll"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#list").jqGrid({
url: '/Test/gridview/',
datatype: "json",
colNames: ['Dataid', 'Name', 'Emailid'],
colModel :[
{ name: 'Dataid', index: 'Dataid', width: 40, align: 'left' },
{ name: 'Name', index: 'Name', width: 40, align: 'left' },
{ name: 'Emailid', index: 'Emailid', width: 200, align: 'left' }],
pager: jQuery('#pager'),
rowNum:10,
sortname: 'Dataid',
sortorder: "desc",
viewrecords: true,
caption: "My grid"
});
});
</script>
and this the output
{"total":1,"page":1,"records":11,"rows":[{"id":18,"cell":["18","aditya","cast@gmail.com"]},{"id":19,"cell":["19","anil","anil@gmail.com"]},{"id":20,"cell":["20","cast","cast@gmail.com"]},{"id":21,"cell":["21","revision","revision@gmail.com"]},{"id":22,"cell":["22","sham","adityakashyap@gmail.com"]},{"id":23,"cell":["23","anil","aditya@gmail.com"]},{"id":24,"cell":["24","sham",null]},{"id":25,"cell":["25","anil","adityakashyap@gmail.com"]},{"id":26,"cell":["26","sudarshan","sudarshan@gmail.com"]},{"id":27,"cell":["27","board","board@gmail.com"]},{"id":28,"cell":["28","seen ","seen@gmail.com"]}]}
can anybody help me out