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

Getting database data using EF

1 Answer 167 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gurdip
Top achievements
Rank 1
Gurdip asked on 16 Nov 2019, 01:03 AM

Hi

I have this code in ASP.NET to bind a data grid to a data source returned from EF:

 

Code:

--------

        @(Html.Kendo().Grid<GarageBookingApp.Models.AdminViewModel>().Name("grid")
                        .Groupable()
                        .Sortable()
                        .Editable()
                        .Scrollable()
                        .ToolBar(x => x.Create())
                        .Columns(columns =>
                        {
                            columns.Bound(column => column.businessTimes.opening);
                            columns.Bound(column => column.businessTimes.closing);
                        
                            columns.Command(column =>
                            {
                                column.Edit();
                                column.Destroy();
                            }).Width(230);
                        })
                        .DataSource(ds => ds.Ajax()
                                .Read(r => r.Action("GetBusinessTimes", "Home"))
                            .PageSize(10)
                        )
                        .Pageable()
        )

 

The controller method is like this:

            using (GarageContext gtx = new GarageContext())
            {
                return gtx.BusinessTimes.Select(businessTimes => new BusinessTimesEntity
                {
                    closing = businessTimes.closing,
                    opening = businessTimes.opening

                }).ToList();

 

I also notice that in the model, the properties are only "getted" but not set".

 

What am I missing to retrieve the database fields correctly here?

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 20 Nov 2019, 03:40 PM

Hi Gurdip,

Thank you for sharing your Grid implementation.

Looking at it I do not notice anything obviously wrong. Yet, in the Controller, I see that the ActionResult method does not return ToDataSourceResult. The ToDataSourceResult is simply an IQueryable extension that translates and handles filtering, sorting, grouping and aggregates. It works together with DataSourceRequest. 

Please modify the Controller so the ActionResult method returns a DataSourceResult and let me know if this resolves the situation.

    For your convenience, I am attaching a sample demo implementing Kendo Grid supporting CRUD (Create, Read, Update, Destroy) data operations. Please review it and let me know if you have any questions.

    Regards,
    Nikolay
    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
    Gurdip
    Top achievements
    Rank 1
    Answers by
    Nikolay
    Telerik team
    Share this question
    or