Empty Grid

5 posts, 0 answers
  1. Joe
    Joe avatar
    62 posts
    Member since:
    May 2012

    Posted 23 Jun Link to this post

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

     

  2. Joe
    Joe avatar
    62 posts
    Member since:
    May 2012

    Posted 23 Jun in reply to Joe Link to this post

    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...
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Joe
    Joe avatar
    62 posts
    Member since:
    May 2012

    Posted 23 Jun Link to this post

    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.

  5. Joe
    Joe avatar
    62 posts
    Member since:
    May 2012

    Posted 23 Jun Link to this post

    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...

  6. Joe
    Joe avatar
    62 posts
    Member since:
    May 2012

    Posted 23 Jun Link to this post

    Sorry for the double post... had gotten an error upon the submission of the first, even though it apparently saved after all....
Back to Top
UI for ASP.NET MVC is VS 2017 Ready