I am attempting to have an ajax grid that does server side paging. (For reference, I am using Entity Framework for db context, and Automapper for model to view model mapping). The paging is working clientside, but it just pulls in all the data from my db then pages. I cannot seem to get the paging to reflect at the sql query level without doing it manually (which defeats the purpose of passing the request to the DataSourceResult(). Am i missing something, or must i do this manually?
Below is my current code:
Razor page
01.
@(Html.Kendo()
02.
.Grid<AgencyContactViewModel>()
03.
.Name(
"Grid"
)
04.
.DataSource(dataSource => dataSource
05.
.Ajax()
06.
.Read(read => read.Action(
"Read"
,
"AgencyContact"
))
07.
.PageSize(5)
08.
.ServerOperation(
true
)
09.
)
10.
11.
.Columns(columns =>
12.
{
13.
columns.Bound(o => o.ID).Width(50).Title(
"Id"
);
14.
columns.Bound(o => o.LastName).Width(100).Title(
"Last Name"
);
15.
columns.Bound(o => o.FirstName).Width(100).Title(
"First Name"
);
16.
columns.Bound(o => o.AgencyDescription).Width(175).Title(
"Agency"
);
17.
columns.Bound(o => o.IsActiveFlag)
18.
.ClientTemplate(
"<input type='checkbox' #= IsActiveFlag ? checked = 'checked' : '' # disabled='disabled' ></input>"
)
19.
.Width(15).Title(
"Active"
);
20.
21.
columns.Bound(o => o.AgencyCode)
22.
.ClientTemplate(
"<a href='"
+ Url.Action(
"Edit"
,
"AgencyContact"
) +
"/#=AgencyCode#'>Edit<a/>"
)
23.
.Title(
""
)
24.
.Width(15);
25.
columns.Bound(o => o.AgencyCode)
26.
.ClientTemplate(
"<a href='"
+ Url.Action(
"Details"
,
"AgencyContact"
) +
"/#=AgencyCode#'>Details<a/>"
)
27.
.Title(
""
)
28.
.Width(15);
29.
})
30.
.Groupable()
31.
.Sortable()
32.
.Pageable()
33.
.Filterable())
Controller
1.
public
JsonResult Read([DataSourceRequest] DataSourceRequest request)
2.
{
3.
var agencyContacts = dbContext.AgencyContacts.Include(
"Agency"
) .OrderBy(a => a.AgencyCode);
4.
var agencyContactsViewModel = agencyContacts.ProjectTo<AgencyContactViewModel>();
5.
var result = agencyContactsViewModel.ToDataSourceResult(request);
6.
return
Json(result, JsonRequestBehavior.AllowGet);
7.
}