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

Data does not display in the Kendo Grid MVC ASP.NET Core

2 Answers 1476 Views
Grid
This is a migrated thread and some comments may be shown as answers.
GalaxyDev
Top achievements
Rank 1
GalaxyDev asked on 11 Oct 2020, 05:10 PM

I am trying out fairly basic databinding with hard coded data using Kendo Grid using MVC - ASP.NET Core. The Grid renders fine and the .read method is called. It returns JSON however, the data does not display in the grid. I verified no errors related to aspnet-mvc.js script. The required scripts are listed only once and in the correct order. Help appreciated. I tried using JsonResult. No luck. 

 

@using Kendo.Mvc.UI
@model IEnumerable<GridPortal.Web.Models.Company>
 
  <script src="~/lib/kendo/2020.1.406/js/kendo.all.min.js"></script>
  <script src="~/lib/kendo/2020.1.406/js/kendo.web.min.js"></script>
  <script src="~/lib/kendo/2020.1.406/js/kendo.aspnetmvc.min.js"></script>
 
 
  <div style="width:100%;height:60%">
   @(Html.Kendo().Grid<GridPortal.Web.Models.Company>() .Name("BindGridUsingRead")
   .Columns(columns => {
   columns.Bound(p => p.Id).Width(15).Title("ID").Filterable(false);
   columns.Bound(p =>  p.Name).Title("Name").Width(30).Filterable(false);
   columns.Bound(p =>  p.CompanyId).Title("CompanyID").Width(15).Filterable(false);
   })
  .Scrollable()
  .Pageable()
  .Filterable(ftp => ftp.Mode(GridFilterMode.Row))
  .Resizable(resize => resize.Columns(true))
  .HtmlAttributes(new { style = "height: 100%" })
  .Selectable()
  .DataSource(dataSource => dataSource
  .Ajax()
  .Model(model => model.Id(p => p.Id))
  .ServerOperation(false)
  .Read(read => read.Action("BindGrid", "Home"))) )
  </div>
public ActionResult BindGrid([DataSourceRequest] DataSourceRequest request)
{
  var company = new List<Company>();
  company.Add(new Company
  {
    CompanyId = 102,
    Id = 1,
    Name = "John Smith"
  });
            
DataSourceResult result = company.ToDataSourceResult(request);
return Json(result);       
}

 

public void ConfigureServices(IServiceCollection services)
{
  services.AddControllersWithViews();
  services.AddKendo();
  services.AddMvc().AddNewtonsoftJson(o =>
  {
o.SerializerSettings.ReferenceLoopHandling =  ReferenceLoopHandling.Ignore;
            }).SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_3_0);
}

2 Answers, 1 is accepted

Sort by
0
GalaxyDev
Top achievements
Rank 1
answered on 11 Oct 2020, 08:46 PM

Actually I see errors with the source map files. How can I fix this  ? 

DevTools failed to load SourceMap: Could not load content for https://localhost:44385/lib/kendo/2020.1.406/js/kendo.all.min.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

DevTools failed to load SourceMap: Could not load content for https://localhost:44385/lib/kendo/2020.1.406/js/kendo.web.min.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

DevTools failed to load SourceMap: Could not load content for https://localhost:44385/lib/kendo/2020.1.406/js/kendo.aspnetmvc.min.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

DevTools failed to load SourceMap: Could not load content for https://localhost:44385/lib/kendo/2020.1.406/styles/kendo.common-nova.min.css.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

DevTools failed to load SourceMap: Could not load content for https://localhost:44385/lib/kendo/2020.1.406/styles/kendo.common.min.css.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

DevTools failed to load SourceMap: Could not load content for https://localhost:44385/lib/kendo/2020.1.406/styles/kendo.nova.min.css.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

1
GalaxyDev
Top achievements
Rank 1
answered on 12 Oct 2020, 11:31 AM

The issue is resolved. Data is binding fine. Added this to the startup.cs 

services.AddControllersWithViews() .AddNewtonsoftJson(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); });

Jim
Top achievements
Rank 1
Iron
Iron
commented on 20 Jan 2024, 04:47 PM

Thanks for posting the answer. Had the same issue.
Tags
Grid
Asked by
GalaxyDev
Top achievements
Rank 1
Answers by
GalaxyDev
Top achievements
Rank 1
Share this question
or