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

Kendo grid does not bind data on datasoruce bind but binds on page refresh

4 Answers 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Naga
Top achievements
Rank 1
Naga asked on 03 Jul 2020, 03:39 PM

     I have implemented a simple Kendo grid in ASP .Net Core which should bind the data on DataSoruce Read request. In actual it is not binding data in read request but binds the data whenever i click on 'refresh' icon under pagination. Below is my code - 

 

<div class="grid-container">

        @(Html.Kendo().Grid<CAMPv2.Models.AutoPoco.Role>()
    .Name("RolesGrid")
    .Columns(columns =>
    {
        columns.Bound(c => c.Name);
        columns.Bound(c => c.NormalizedName);
        columns.Bound(c => c.Description);
        columns.Bound(c => c.Status);
    })    
    .Scrollable()
    .Sortable()
    .Pageable(pageable => pageable
    .Refresh(true)
    .PageSizes(true)
    .ButtonCount(5))
    .DataSource(datasource => datasource
    .Ajax()
    .Read(read => read.Action("GetRoles", "Role"))

    )
    )
    </div>

 

Below is code behind - 

[HttpPost]
        public IActionResult GetRoles([DataSourceRequest] DataSourceRequest request)
        {
            List<Role> _lrolePermissionDetails = _tableOperations.GetAll<Role>(ApplicationConstants.CONNECTOR_AUTOPOCOAUTH, "Role", _loggingService).ToList();
            return Json(_lrolePermissionDetails.ToDataSourceResult(request));           
        }

 

Please let me know what i am missing here.

Thanks,

Naga

 

 

4 Answers, 1 is accepted

Sort by
0
Naga
Top achievements
Rank 1
answered on 03 Jul 2020, 04:08 PM

I have also added below scripts in _Layout page - 
<script src="~/lib/Kendo-UI/js/kendo.all.min.js"></script>
<script src="~/lib/Kendo-UI/js/kendo.aspnetmvc.min.js"></script>

Startup.cs has below code as well - 
services.AddMvc().AddJsonOptions(options =>

{
      options.SerializerSettings.ContractResolver = new DefaultContractResolver();
 });
services.AddKendo();


0
Nikolay
Telerik team
answered on 08 Jul 2020, 10:39 AM

Hello Naga,

Thank you for sharing the Grid declaration.

If the Grid binds to the data on the Refresh button click but not on loading I suppose there is something preventing it from that. Maybe a script or AutoBind property set to false?

Additionally, I could suggest serializing the JSON in CamelCase by locating the ConfigureServices method in the project and adding the below

public void ConfigureServices(IServiceCollection services)
{
    ...
    // Maintain the property names during serialization.
    // For more information, refer to https://github.com/aspnet/Announcements/issues/194.
    services
        .AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
        .AddJsonOptions(options =>
            options.SerializerSettings.ContractResolver = new DefaultContractResolver());

    services.AddKendo();
}

More information can be obtained in the following documentation page:

Let me know if this helps.

Regards,
Nikolay
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Naga
Top achievements
Rank 1
answered on 08 Jul 2020, 04:43 PM

Hi Nikolay,

 

Thank you for your reply.

I have already added these settings to the startup and also set AutoBind(true) explicitly. Grid always shows data on pager refresh icon but not on load. I am using .Net Core 2.2 framework.

Thanks,

Sameer

0
Nikolay
Telerik team
answered on 13 Jul 2020, 09:22 AM

Hi Naga,

Thank you for getting back to me.

This behavior is quite unusual and based on the provided it is hard to tell what might be the cause of it.

For your convenience, I am attaching a small MVC Core project implementing a Kendo UI Grid Ajax bound to the controller. The data is correctly loaded initially. Please examine it and let me know if this gives any hints on the situation.

Alternatively, I could best advise you to submit a support thread attaching a sample runnable page that clearly replicates and isolates the problem. Examining this page locally will help us fully understand the case and investigate further.

Regards,
Nikolay
Progress Telerik

Tags
Grid
Asked by
Naga
Top achievements
Rank 1
Answers by
Naga
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or