This is a migrated thread and some comments may be shown as answers.

Problem with Grid Data Binding on Ajax Calls

3 Answers 162 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nathan
Top achievements
Rank 1
Nathan asked on 11 Oct 2012, 04:52 AM
Hopefully this is an easy one :)

I have a "Membership" Controller that serves up a WebsiteUser obect defined as so:
public class WebsiteUser
{
    public string UserName { get; set; }
    public DateTime LoginTime { get; set; }
    public bool IsLoggedIn { get; set; }
}

This is served up from the Membership/Index route:

       
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);
}


Which is populated thusly:
@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")
        )
    )
)


It all works quite nicely until I try to do paging, sorting or other ajax calls. The grid simply empties.

Whacking a breakpoint on the Index() call the page is definitely calling it back, but we're not getting the data. I assume I'm doing something elementary wrong here, unfortunately the Razor guides are still a little sparse on the ground and I'm having trouble finding a Razor example that does what I need.

3 Answers, 1 is accepted

Sort by
0
Nathan
Top achievements
Rank 1
answered on 12 Oct 2012, 12:38 AM
Raised a support ticket instead.
0
Mic
Top achievements
Rank 1
answered on 15 Nov 2012, 02:12 PM
Did You get any solution to that?
0
Nathan
Top achievements
Rank 1
answered on 15 Nov 2012, 11:03 PM

This was the reply I got from support, I haven't had a chance to implement the recommendations yet:

"Looking at the provided code snippets it seems that the Grid is not correctly configured for AJAX binding. The Action set for the AJAX Read is returning the entire Index View instead of only the data wrapped in a JsonResult. Please refer to this documentation article on how to configure Grid widget for AJAX binding."

Hope that helps :)

Tags
Grid
Asked by
Nathan
Top achievements
Rank 1
Answers by
Nathan
Top achievements
Rank 1
Mic
Top achievements
Rank 1
Share this question
or