Jagannath Mahapatra Jagannath Mahapatra - 3 months ago 9
jQuery Question

In jqGrid data is not binding, showing blank grid

<script type="text/javascript">
$(document).ready(function () {

$("#list").jqGrid({
url: 'SampleController/jqGrid1',
datatype: "json",
mtype: 'GET',
colNames: ['Id', 'Name', 'Mobile', 'Email', 'City', 'State', 'Gender'],
colModel: [{ name: 'Id', index: 'Id', width: 100 },
{ name: 'Name', index: 'Name', width: 100 },
{ name: 'Mobile', index: 'Mobile', width: 100 },
{ name: 'Email', index: 'Email', width: 100 },
{ name: 'City', index: 'City', width: 100 },
{ name: 'State', index: 'State', width: 100 },
{ name: 'Gender', index: 'Gender', width: 100 }
],
sortname: 'Id',
rowNum: 10,
loadonce: true,
viewrecords: true,
caption: 'List of Students',
scrollOffset: 0,
gridview: true,
autoencode:true
});

});



controller code:

public JsonResult jqGrid1()
{
return Json(objDB.SelectALL(), JsonRequestBehavior.AllowGet);
}


objDB.SelectAll()
returns a List
is there any mistake Please inform. When i debug the code it is not calling the method
jqGrid1()
of sample controller.

Div Div
Answer

Change this:

url: 'SampleController/jqGrid1',

To

url: '/Sample/jqGrid1',

OR Use the Url.Action helper method to generate the correct relative url to the action method.

url: '@Url.Action("jqGrid1","Sample")',

When razor executes the code for your view, it will run the Url.Action method and output the correct URL(which will have the controller name if needed).

Edit:
As per comment jqGrid data is not binding, showing blank grid You have to return the JSON data in the proper format with the necessary parameters.

For ex.

return Json(new{
                 total = 1,
                 page = 1,
                 records = yourCount, // actual data count
                 rows = objDB.SelectALL()// actual data
              });