Click here to Skip to main content
15,120,739 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have json object in my controller which is not binding to jqGrid of GET method.


Controller.cs
---------------------
C#
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
-------------
HTML
<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>



JavaScript
//    var mydata = [
    //{ "PaymentDate": "01/01/2015", "PayeeName": "test", "SrcDocType": "Check", "Amount": 100, "CheckNumber": 1234, "ObjectCode": 4525 },
    //  { "PaymentDate": "01/01/2015", "PayeeName": "test", "SrcDocType": "Check", "Amount": 100, "CheckNumber": 1578, "ObjectCode": 4525 }
    //    ];
    $(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.

JavaScript
//var result = new
            //{

            //    total = 10,
            //    Page = page.ToString(),
            //    records = "1",
            //    rows = GetKFSList()
            //};
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..?
Posted
Updated 20-Oct-17 12:06pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900