ParamQuery grid support forum

General Category => Help for ParamQuery Grid (free version) => Topic started by: Eagle_f90 on January 22, 2016, 01:16:45 am

Title: Unable to load data into Grid from MVC JsonResult
Post by: Eagle_f90 on January 22, 2016, 01:16:45 am
After digging around on the board I was able to modify a demo to call into an MVC 6 JsonResult Action but I can not get the data to load into the grid. I can enter debug mode in Visual Studio and do see the AJAX call into the Action and that the action is returning a result containing 1 record (which is the right amount of records). The grid then load into the web page but no data inside is displayed just the words "No rows to Display." What am I doing wrong?

JavaScript Code:

Code: [Select]
<script>
    $(function ()
    {
        var colModel = [
            { title: "ID", width: 100, dataType: "integer", dataIndx: "ID" },
            { title: "Name", width: 500, dataType: "string", dataIndx: "Name" }
        ];

        var dataModel =
        {
            location: "remote",
            dataType: "json",
            method: "POST",
            contentType: "application/json; charset=UTF-8",
            url: '@Url.RouteUrl("GetChangeOrders")',
            getData: function (dataJson)
            {
                var data = dataJson.data;
                return { data: data };
            }
        };

        var obj =
        {
            title: "Test",
            dataModel: dataModel,
            colModel: colModel,
        };

        $("#Grid").pqGrid(obj);

    });
</script>

c# Code:
Code: [Select]
        [Route("GetChangeOrders", Name = "GetChangeOrders")]
        public JsonResult ChangeOrders()
        {
            var ChangeOrdersList = _DbContext.ChangeOrders.Select(co => new { ID = co.ID, Name = co.Name }).ToList();

            return Json(ChangeOrdersList);
        }
Title: Re: Unable to load data into Grid from MVC JsonResult
Post by: paramvir on January 22, 2016, 01:35:10 pm
in your case:

Code: [Select]
getData: function (dataJson)
{
      return { data: dataJson };
}
Title: Re: Unable to load data into Grid from MVC JsonResult
Post by: Eagle_f90 on January 22, 2016, 07:02:40 pm
Thank you very much, that worked.