Server binding kendo grid without exposing database context in the controller

4 posts, 0 answers
  1. Leah
    Leah avatar
    5 posts
    Member since:
    Apr 2018

    Posted 30 Apr Link to this post

    Hi,

    I am expecting a large amount of data to be displayed in the grid and used paging. I tried to use the Kendo.Mvc.Extensions ToDataSourceResult method but don't want to expose my context in the controller. Is there any way to achieve this?

  2. Georgi
    Admin
    Georgi avatar
    370 posts

    Posted 02 May Link to this post

    Hello Leah,

    I would recommend you to use a Service Layer. In other words create a separate classes called "services". Put them in different class library (or namespace) project and make them independent on MVC framework infrastructure. 

    You will find a sample which demonstrates the usage of a Service Layer in the link below:



    Regards,
    Georgi
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Leah
    Leah avatar
    5 posts
    Member since:
    Apr 2018

    Posted 03 May in reply to Georgi Link to this post

    Hi Georgi,

    I found a simple solution in stackoverflow by doing the code below.

    The repository method with no reference to Kendo:

    public T GetSales<T>(Func<IQueryable<SalesOrderHeader>, T> processQueryable)
    {
        using (var c = new AdventureWorks2012Context())
        {
            return processQueryable(c.SalesOrderHeaders);
        }
    }

    To use it you need a function to process the iqueryable as parameter, in this case it returns a DataSourceResult:

    public JsonResult Post([DataSourceRequest] DataSourceRequest request)
    {
        DataSourceResult sales = salesService.GetSales<DataSourceResult>
               (headersQuery=>headersQuery.ToDataSourceResult(request));
     
        return Json(sales , JsonRequestBehavior.AllowGet);
    }
  4. Georgi
    Admin
    Georgi avatar
    370 posts

    Posted 08 May Link to this post

    Hello Leah,

    I am glad to hear that you managed to resolve your query and thank you for sharing your solution with the community.

    In case further questions related to the initial one arise at any point, you can reply to this thread.
     

    Regards,
    Georgi
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top