How to use Kendo UI Grid with ToDataSourceResult(), IQueryable, ViewModel and AutoMapper?

前端 未结 6 1679
轻奢々
轻奢々 2021-02-02 01:00

What is the best approach to load/filter/order a Kendo grid with the following classes:

Domain:

public class Car
{
    public virtual in         


        
6条回答
  •  我在风中等你
    2021-02-02 01:24

    I came across this same issue and after lots of research I resolved it permanently by using AutoMapper.QueryableExtensions library. It has an extension method that will project your entity query to your model and after that you can apply ToDataSourceResult extension method on your projected model.

    public ActionResult GetData([DataSourceRequest]DataSourceRequest request)
    {
         IQueryable entity = getCars().ProjectTo();
         var response = entity.ToDataSourceResult(request);
         return Json(response,JsonRequestBehavior.AllowGet);
    }
    

    Remember to configure Automapper using CreateMap.

    Note: Here getCars will return IQueryable result car.

提交回复
热议问题