I have the following code which is far as I can tell as per the documentation and examples but the listview always appears empty.
My View is as follows
@model iProjX.Models.RolesModel@using iProjX.Models;<script type="text/x-kendo-tmpl" id="rolesList"> <h3> ${Id} ${Description}</h3></script><div id="listView"></div><div class="k-pager-wrap"> <div id="pager"></div></div><script type="text/javascript"> var projectId = @(Html.Raw(Model.ProjectId)); var sharedDataSource = new kendo.data.DataSource({ transport: { read: { url: "http://localhost:1278/Project/getRoles", type: "POST" } }, change: function (data) { debugger; alert("success "); }, error: function (xhr, error) { debugger; alert("error "); }, pageSize: 3 }); //Configure the List $("#listView").kendoListView({ pageable: true, selectable: true, navigatable: true, template: kendo.template($("#rolesList").html()), dataSource: sharedDataSource }); //Configure the Pager $("#pager").kendoPager({ dataSource: sharedDataSource }); </script>
And my controller contains
public JsonResult getRoles([DataSourceRequest] DataSourceRequest request) { var projectId = 113; using (LocationRepositry _locationRepository = new LocationRepositry()) { IEnumerable<myLocation> Locations = _locationRepository.getByProjectId_Simple(projectId).Select(p => new myLocation() { Id = p.Id, Description = p.Description }).ToList(); return Json(Locations.ToDataSourceResult(request)); }}And myLocation is
public class myLocation{ public myLocation() {} public Int64 Id { get; set; } public String Description { get; set; }}Now, with this implementation my controller function getRoles is hit and I can see the data returned from the server via browser tools as below.
Data returned from server
{"Data":[{"Id":132,"Description":"Location 1"},{"Id":133,"Description":"Location 2"},{"Id":134,"Description":"Location 3"},{"Id":135,"Description":"Location 4"}],"Total":4,"AggregateResults":null,"Errors":null}
The change function on the datasource is then subsequently hit but the data parameter returned contains an empty set of Data items as below (taken from visual studio immediate window).
?data{...} items: [] sender: {...} preventDefault: function(){g=!0} isDefaultPrevented: function(){return g}
If I change my controller to return without using the ToDataSourceResult extension it actually will work.
return Json(Locations);
However, is this then the correct implementation or have I done something else wrong? And would this have an effect on how paging works?
Any help would be much appreciated.
Thanks