0

I am using the Telerik kendo data grid I am using a web API to get the data back into my grid if we look at the following. The following is how I have defined my kendo read method the only difference to this app from ones I have got working before is I am using .net core 3.1

I have this added as per the Telerik documentation.

https://docs.telerik.com/kendo-ui/knowledge-base/grid-is-not-showing-data but still no data in the grid as you can see below.

@(Html.Kendo().Grid<Stock>()
.Name("Grid")
.Columns(columns =>
{
    columns.Bound(p => p.ID);
    columns.Bound(p => p.Description).Width(180);
    columns.Bound(p => p.Name).Width(180);
    columns.Command(command => command.Destroy()).Width(160);
})
.ToolBar(toolbar =>
{
    toolbar.Create();
    toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Navigatable()
.Sortable()
.Groupable()
.Filterable()
.Scrollable()
.DataSource(dataSource => dataSource
    .Ajax()
    .Batch(true)
    .PageSize(20)
    .ServerOperation(false)
    .Events(events => events.Error("error_handler"))
      .Model(model =>
    {
        model.Field(p => p.ID).Editable(false);
        model.Field(p => p.Name);
    })
     .Read("ReadStock", "Stock")
   )
)


public async Task<IActionResult> ReadStock([DataSourceRequest] DataSourceRequest request)
{
    List<Stock> _result = new List<Stock>();
    _result =await  apiClient.GetStockFromApi();
    object test  = Json(_result);
    return Json(_result);
}

If we look in the below you will see that I have data fine.

enter image description here

But when you see my grid it is empty

enter image description here

I have added the correct contract resolver for json.net but yet there is no data in my grid. In my startup cs I have the following.

 services
            .AddControllersWithViews()
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
            // Maintain property names during serialization. See:
            // https://github.com/aspnet/Announcements/issues/194
            .AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());

My Stock Class.

public class Stock
{
        public int ID { get; set; } // int, not null
        public string StockCode { get; set; } // nvarchar(150), null
        public string Name { get; set; } // nvarchar(350), not null
        public string Description { get; set; } // nvarchar(max), null
        public DateTime? StartDate { get; set; } // datetime, null
        public DateTime? EndDate { get; set; } // datetime, null
        public int? WarehouseId { get; set; } // int, null
        public int? IsFreeText { get; set; } // int, null
        public decimal? QuanityInStock { get; set; } // decimal(18,5), null
        public decimal? RecordedQuantity { get; set; } // decimal(18,5), null
        public bool? UseDescription { get; set; } // bit, null
        public string Barcode { get; set; } // nvarchar(50), null
        public int? ProductGroup { get; set; } // int, null
        public int? TaxCode { get; set; } // int, null
        public decimal? PhysicalStock { get; set; } // decimal(18,5), null
        public decimal? ActualStock { get; set; } // decimal(18,5), null
        public bool? isActive { get; set; } // bit, null
        public bool? isDeleted { get; set; } // bit, null
        public DateTime? CreatedDate { get; set; } // datetime, null
        public string CreatedBy { get; set; } // varchar(100), null
        public string UOM { get; set; } // nvarchar(50), null
  }
c-sharp-and-swiftui-devni
  • 3,743
  • 4
  • 39
  • 100

1 Answers1

0

To Fix this you need to do this in a .net core 3.1 app.

services.AddMvc(setupAction=> {
        setupAction.EnableEndpointRouting = false;
    }).AddJsonOptions(jsonOptions =>
    {
        jsonOptions.JsonSerializerOptions.PropertyNamingPolicy = null;
    })
    .SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
c-sharp-and-swiftui-devni
  • 3,743
  • 4
  • 39
  • 100