@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
public
class
WebsiteUser
{
public
string
UserName {
get
;
set
; }
public
DateTime LoginTime {
get
;
set
; }
public
bool
IsLoggedIn {
get
;
set
; }
}
public
ActionResult Index()
{
List<WebsiteUser> Users =
new
List<WebsiteUser>();
foreach
(MembershipUser user
in
Membership.GetAllUsers())
{
Users.Add(
new
WebsiteUser()
{
UserName = user.UserName,
IsLoggedIn = user.IsOnline,
LoginTime = user.LastActivityDate
});
}
return
View(Users);
}
@model IEnumerable<
ATFWebsite.Controllers.WebsiteUser
>
@{
ViewBag.Title = "Index";
}
<
h2
>Membership</
h2
>
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.UserName).Groupable(false);
columns.Bound(p => p.IsLoggedIn);
columns.Bound(p => p.LoginTime);
})
.Groupable()
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Index", "Membership")
)
)
)