Grid not displaying any records in .NET Core 3.1

5 posts, 0 answers
  1. Nick Gilbert
    Nick Gilbert avatar
    4 posts
    Member since:
    Aug 2012

    Posted 19 Mar 2020 Link to this post

    I've ported my app from .NET Framework MVC to .NET Core 3.1.  The Kendo Grid displays OK and fetches data from the controller successfully (no javascript console errors). However despite the fact that 10 records are returned, the grid isn't actually rendering any rows.   What could I be doing wrong?

    Controller:

    public ActionResult FetchUsers([DataSourceRequest] DataSourceRequest request)
    {
        var cardivationApi = GetCardivationApi();
        var data = cardivationApi.GetUsersFiltered(request);
        return new JsonResult(data);

    }

     

    View:

    @(Html.Kendo().Grid<UserDtoV1>().Name("grid")
                  .Columns(columns =>
                  {
                      columns.Bound(p => p.FirstName).Title(DbRes.T("FirstName", "Labels"))
                          .Filterable(t => t.Cell(cell => cell.Operator("startswith").SuggestionOperator(FilterType.StartsWith).Delay(9999))
                              .Operators(o => o.ForString(d => d.Clear().StartsWith(DbRes.T("StartsWith", "Labels")).Contains(DbRes.T("Contains", "Labels"))))
                              .Extra(false));
                      [ cut for brevity ]
                         
                       
                    .Pageable(p => p.PageSizes(true).PageSizes(new[] { 10, 20, 50, 100 }).Messages(t => t.ItemsPerPage(DbRes.T("ItemsPerPage", "Labels"))))
                    .Filterable(ftb => ftb.Mode(GridFilterMode.Menu))
                    .HtmlAttributes(new { style = "min-height:500px;" })               
                    .ProxyURL(Url.Action("ExcelExport", "Users"))
                )
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .PageSize(10)
                    .ServerOperation(true)
                    .Read(read => read.Action("FetchUsers", "Users"))
                    .Model(model => model.Id(t => t.UserID))
                )
            )

     

     

    Thanks,

    Nick

  2. Eyup
    Admin
    Eyup avatar
    4079 posts

    Posted 20 Mar 2020 Link to this post

    Hello Nick,

     

    Usually this happens due to the lack of one setting - for Core projects with Grid, also make sure that you have the following setting added to your project:
    .AddJsonOptions(options =>
                options.SerializerSettings.ContractResolver = new DefaultContractResolver());

    As mentioned here:
    https://docs.telerik.com/aspnet-core/getting-started/getting-started
     

     

    Regards,
    Eyup
    Progress Telerik

    Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
  3. Vincent
    Vincent avatar
    56 posts
    Member since:
    Dec 2013

    Posted 28 Mar 2020 Link to this post

    In .NET core 3.1, you must set as follow:

     services.AddRazorPages().AddRazorPagesOptions(options =>
                {
                    options.Conventions.AuthorizePage("/_Layout");
                    options.Conventions.AuthorizePage("/_ValidationScriptsPartial");
                    options.Conventions.AuthorizePage("/_ViewImports");
                    options.Conventions.AuthorizePage("/_ViewStart");
                    options.Conventions.AuthorizePage("/Helper");
                    options.Conventions.AuthorizePage("/Index");
                }).AddNewtonsoftJson(options =>
                options.SerializerSettings.ContractResolver = new DefaultContractResolver());//for razor page

  4. Gurdip
    Gurdip avatar
    3 posts
    Member since:
    Aug 2019

    Posted 19 Aug 2020 in reply to Eyup Link to this post

    I have this in my startup. Is this not correct?

     

        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());

  5. Eyup
    Admin
    Eyup avatar
    4079 posts

    Posted 19 Aug 2020 Link to this post

    Hi Gurdip,

     

    I've sent you a working sample in the official support thread. I suggest that we continue our technical conversation there.

     

    Regards,
    Eyup
    Progress Telerik

Back to Top