I have json object in my controller which is not binding to jqGrid of GET method.
Controller.cs
---------------------
public ActionResult Index()
{
return View();
}
[HttpGet]
public JsonResult ImportKFSData(int rows,string sidx,string sord,int page)
{
string startDate = "01/01/2016";
string endDate = "01/15/2016";
var _KFSImportList = KFSPaymentDetailList.GetKFSImportList(Convert.ToDateTime(startDate),Convert.ToDateTimeendDate));
var result = new
{
total = 10,
Page = page.ToString(),
records = "1",
Data = _KFSImportList.Select(x => new
{
x.PaymentDate,
x.PayeeName,
x.SrcDocType,
x.Amount,
x.CheckNumber,
x.ObjectCode
}).ToArray()
};
return Json(result,JsonRequestBehavior.AllowGet);
}
Index.cshtml
-------------
<div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
<table id="KFSImporttbl" class="1099MiscJQGrid table table-bordered table-striped" style="table-layout: fixed; height: 200px"></table>
<div id="pager"></div>
</div>
$(document).ready(function () {
debugger;
$('#KFSImporttbl').jqGrid({
datatype: 'json',
mtype: 'GET',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
url: '@Url.Action("ImportKFSData", "KFSReportablePayments")',
colNames: ['PaymentDate', 'PayeeName', 'SrcDocType', 'Amount', 'Check Number', 'Object Code'],
colModel: [
{ name: 'PaymentDate', index: 'PaymentDate', width: 20 },
{ name: 'PayeeName', index: 'PayeeName', width: 50 },
{ name: 'SrcDocType', index: 'SrcDocType', width: 20 },
{ name: 'Amount', index: 'Amount', width: 15 },
{ name: 'CheckNumber', index: 'CheckNumber', width: 20 },
{ name: 'ObjectCode', index: 'ObjectCode', width: 10 }
],
gridview: true,
rowNum: 10,
rowList: [10, 20, 30],
pager: '#pager',
viewrecords: true,
autowidth: true,
height: 'auto',
width: 'auto',
success: function () {
},
}).navGrid("#pager", { edit: false, add: false, del: false });
});
What I have tried:
Actually I was trying to bind dynamic data.
I have tried with local data which i was mentioned in index.cshtml page.
It was working fine.
When I have given static data from controller.it was not binding.
I didn't see any error in console while i am trying with dynamic or static object.
return Json(result,JsonRequestBehavior.AllowGet);<
private List<kfspaymentdetail> GetKFSList()
{
var KFSPaymentList = new List<kfspaymentdetail>();
{
KFSPaymentList.Add(new KFSPaymentDetail
{
PaymentDate = Convert.ToDateTime("01/01/2015"),
PayeeName = "test",
SrcDocType = "AM",
Amount = 100,
CheckNumber = 12541,
ObjectCode = 4525
});
};
return KFSPaymentList;
}
Can any one help me what I am missing..?