This is a migrated thread and some comments may be shown as answers.

Kendo Core Grid not populating - Custom Ajax

3 Answers 292 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 31 Oct 2018, 12:29 PM

All,

I am having a heck of a time with a very basic implementation using custom Ajax binding.

My implementation is extremely simple. I have verified that the JSON result is returned as CamalCase (Hence the KendoSerializerSettings).

Please see below.

Controller

public ActionResult YearRead([DataSourceRequest]DataSourceRequest request)
        {
            IEnumerable<VehMetaYearDto> years = _metaService.GetYears();
 
            DataSourceResult result = years.ToDataSourceResult(request);
 
            return Json(result, KendoSerializerSettings);
        }

 

JSON Result

{
  "Result": {
    "Data": [
      {
        "Year": 2017,
        "IsDeleted": false,
        "DeleterUserId": null,
        "DeletionTime": null,
        "LastModificationTime": null,
        "LastModifierUserId": null,
        "CreationTime": "2018-10-30T12:15:48.1414343",
        "CreatorUserId": null,
        "Id": 1
      },
      {
        "Year": 2016,
        "IsDeleted": false,
        "DeleterUserId": null,
        "DeletionTime": null,
        "LastModificationTime": null,
        "LastModifierUserId": null,
        "CreationTime": "2018-10-31T08:14:16.9153819",
        "CreatorUserId": null,
        "Id": 2
      }
    ],
    "Total": 2,
    "AggregateResults": null,
    "Errors": null
  },
  "TargetUrl": null,
  "Success": true,
  "Error": null,
  "UnAuthorizedRequest": false,
  "__abp": true
}

 

Razor

@(Html.Kendo().Grid<VehMetaYearDto>()
.Name("YearGrid")
.Columns(c =>
 {
      c.Bound(x => x.Year);
  })
 .DataSource(d => d
   .Ajax()                              
   .Read(r => r.Action("YearRead", "VehMetaAdmin"))
     )
   )

 

The grid renders blank sadly.

PS - The code formatting for this forum is very difficult to use

3 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 31 Oct 2018, 03:13 PM

I am using ASPNetZero. After comparing the JSON results to the ones from the Telerik Demo, I noticed that the outer wrapper of the inner "Data" results is present, where there is not one in the Telerik demos.

Is it possible to have the Grid look at the inner "Data" from the "Result"?

Thanks again!

0
Matt
Top achievements
Rank 1
answered on 01 Nov 2018, 02:56 PM

If anyone else hits this problem using ASPNetZero. I originally tried to get the grid to bind to the inner object, which is a very bad idea if you plan on object manipulation using Kendo's built in functions.

Simple fix is below, though, you lose some possible relevant data from ASPNetZero.

Add "[DontWrapResult]" to the controller Action.

[DontWrapResult]
public JsonResult YearRead([DataSourceRequest]DataSourceRequest request)

 

 

0
Alex Hajigeorgieva
Telerik team
answered on 05 Nov 2018, 10:42 AM
Hello, Matt,

Thank you for updating the thread with the solution that you have found.

From a Kendo UI perspective, you can advise the data source to look for the Data array in the result object by specifying a Schema.Data.

The Schema is only available as part of the custom data source:

https://demos.telerik.com/aspnet-core/grid/custom-datasource

.Schema(schema => { schema.Model(m => m.Id(p => p.Id)); schema.Data("Result.Data"); })


This would generate a data source on the client like the one in this runnable example:

https://dojo.telerik.com/@bubblemaster/IXeTASEv

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or