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

Empty Grid

4 Answers 870 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 23 Jun 2016, 08:16 PM

I am trying something simple, or what should be simple.  Creating a Kendo MVC Grid, and populating it via Ajax.  Before you suggest it, I have looked in the developer tools in Chrome, and there are no Javascript errors whatsoever.  No exceptions in the code, and no javascript errors.  It will most likely be something simple, but I just cannot seem to find it.

I have placed a breakpoint in the action in which it should be calling, and it never, ever even calls it.  If it at least called it, I'd know where to start looking, but it never calls it.  And again, no javascript errors whatsoever, as shown in the attached screen capture.

My cshtml page:

@{
    ViewBag.Title = "Index";
}
 
<h2>Index</h2>
 
@(Html.Kendo().Grid<User>()
    .AutoBind(true)
    .Name("userGrid")
    .Columns(cols => {
        cols.Bound(c => c.UserId);
        cols.Bound(c => c.FirstName);
        cols.Bound(c => c.LastName);
        cols.Bound(c => c.UserName);
    })
    .Scrollable()
    .Sortable()
    .Pageable(pageable => pageable
        .Refresh(true)
        .PageSizes(true)
        .ButtonCount(5))
    .DataSource(ds => ds
        .Ajax()
        .Read(r => r.Action("AllUsers", "Home").Type(HttpVerbs.Get))
        .PageSize(20))
)

My Controller is also just as simple:

using System.Collections.Generic;
using System.Web.Mvc;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using TelerikMVC_Template.Models;
using TelerikMVC_Template.Repository;
 
namespace TelerikMVC_Template.Controllers
{
    [Authorize]
    public class HomeController : Controller
    {
        private readonly IUserRepository userRepository = new UserRepository(new VUsersContext());
 
        // GET: Home
        public ActionResult Index()
        {
            return View();
        }
 
        [HttpGet]
        [ActionName("AllUsers")]
        public JsonResult AllUsers([DataSourceRequest]DataSourceRequest request)
        {
            IEnumerable<User> theseUsers = userRepository.SelectAll();
            return Json(theseUsers.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
    }
}

And finally my User class definition:

public class User
{
    public System.Guid UserId { get; set; }
    public string UserName { get; set; }
    public string Email { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Comment { get; set; }
    public string Password { get; set; }
    public System.DateTime LastLoginDate { get; set; }
    public System.DateTime LastPasswordChangedDate { get; set; }
    public System.DateTime CreationDate { get; set; }
    public bool IsLockedOut { get; set; }
    public bool IsActive { get; set; }
    public int FailedPasswordAttemptCount { get; set; }
    public System.DateTime? LastPasswordFailedDate { get; set; }
    public System.DateTime CreatedDate { get; set; }
}

 

4 Answers, 1 is accepted

Sort by
0
Joe
Top achievements
Rank 1
answered on 23 Jun 2016, 08:53 PM
Just as a followup, even looking in the Network tab of the Chrome Development tools, the GET never even attempts to fire...  The Read action should trigger automagically, especially if AutoBind(true) is used, right?  So why won't this work... argh...
0
Joe
Top achievements
Rank 1
answered on 23 Jun 2016, 09:23 PM

Ok, the answer is...

I had forgotten to include:

And the second thing is my User object is an Entity from EntityFrameworks.  I created a UserViewModel and populated it from the results of my SelectAll(), which returned IEnumerable<User>.  Using the ViewModel, it now populates correctly.

Was a turbulent experience for something that should be easy, and something that may have helped was better examples to learn from.

0
Joe
Top achievements
Rank 1
answered on 23 Jun 2016, 09:24 PM

I found it.  I had forgotten to include:

<script src="http://kendo.cdn.telerik.com/2016.2.607/js/kendo.aspnetmvc.min.js"></script>

And I also changed the model from a Entity to a POCO and now the grid populates correctly.  Would've been less of a headache if these types of things had been explained somewhere...

0
Joe
Top achievements
Rank 1
answered on 23 Jun 2016, 09:25 PM
Sorry for the double post... had gotten an error upon the submission of the first, even though it apparently saved after all....
Tags
Grid
Asked by
Joe
Top achievements
Rank 1
Answers by
Joe
Top achievements
Rank 1
Share this question
or