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

not sorting, grouping, or paging - DBContext issue?

5 Answers 149 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Samuel
Top achievements
Rank 2
Samuel asked on 03 Sep 2012, 02:54 AM
I'm trying to follow the examples that I've found, but I seem to be missing something that prevents my results from sorting or grouping or paging. I'm assuming that the problem is in the controller, probably in GetEducators but I can't figure out what it is that I'm missing!

Index.html
@model LicenseVerification.Models.tc_person
 
@{
    ViewBag.Title = "SearchPerson";
}
 
<h2>Index cshtml</h2>
 
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")"type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"type="text/javascript"></script>
 
@using (Html.BeginForm("SearchResults", "PersonSearch"))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>tc_person</legend>
         
        <div class="editor-label">
            @Html.Label("first_name", "First Name")
        </div>
        <div class="editor-field">
            @Html.Editor("first_name", "First Name")
            @Html.ValidationMessageFor(model => model.first_name)
        </div>
 
        <div class="editor-label">
            @Html.Label("last_name", "Last Name")
        </div>
        <div class="editor-field">
            @Html.Editor("last_name", "Last Name")
            @Html.ValidationMessageFor(model => model.last_name)
        </div>
 
        <p>
            <input type="submit" value="Search" />
        </p>
    </fieldset>
}

PersonSearchController.cs
using System.Linq;
using System.Web.Mvc;
using LicenseVerification.Models;
using System.Collections;
 
namespace LicenseVerification.Controllers
{
    public class PersonSearchController : Controller
    {
        private be_cactusEntities db = new be_cactusEntities();
 
        public ActionResult Index()
        {
            return View();
        }
 
        public ActionResult SearchResults(string firstName = ""stringlastName = "")
        {
 
            return View(GetEducators(firstName,lastName));
        }
 
        private IEnumerable GetEducators(string firstName = ""stringlastName = "")
        {
 
            var educators = from e in db.tc_person
                             where e.first_name.Contains(firstName)
                             && e.last_name.Contains(lastName)
                             select e;
            ViewBag.firstName = firstName;
            ViewBag.lastName = lastName;
            return educators;
        }
 
 
        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}

SearchResults.cshtml
@model IEnumerable<LicenseVerification.Models.tc_person>
 
<h2> Without Partial</h2>
 
@{
    string lastName = "NULL";
    string firstName = "NULL";
    if (ViewBag.lastName != null)
    {
        lastName = ViewBag.lastName;
    }
    if (ViewBag.firstName != null)
    {
        firstName = ViewBag.firstName;
    }
         
}
@(Html.Kendo().Grid(Model)
        .Name("Grid")
        .Columns(cols =>
        {
            cols.Bound(p => p.person_id).Groupable(false);
            cols.Bound(p => p.first_name);
            cols.Bound(p => p.last_name);
        })
        .Pageable(pageable => pageable.PageSizes(true).PageSizes(new int[] { 10, 25 }))
        .Sortable()
)
 
<p />
lastName is @lastName<br />
firstName is @firstName

My model is from a DBContext template and Entity Framework, but it is below in case it's relevant:
tc_person.cs
//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
 
using System;
using System.Collections.Generic;
 
namespace LicenseVerification.Models
{
    public partial class tc_person
    {
        public tc_person()
        {
            this.tc_experience = new HashSet<tc_experience>();
            this.tc_license = new HashSet<tc_license>();
            this.tc_certificate = new HashSet<tc_certificate>();
        }
     
        public decimal person_id { getset; }
        public System.DateTime date_record_added { getset; }
        public string prefix { getset; }
        public string last_name { getset; }
        public string first_name { getset; }
        public string middle_name { getset; }
        public string suffix { getset; }
        public string preferred_name { getset; }
        public string maiden_name { getset; }
        public string aka { getset; }
        public string ethnic_code { getset; }
        public string gender { getset; }
        public Nullable<System.DateTime> dob { getset; }
        public Nullable<System.DateTime> deceased_date { getset; }
        public string citizenship { getset; }
        public string nclb_veteran { getset; }
        public Nullable<System.DateTime> ethics_test { getset; }
     
        public virtual ICollection<tc_experience> tc_experience { getset; }
        public virtual ICollection<tc_license> tc_license { getset; }
        public virtual ICollection<tc_certificate> tc_certificate { getset; }
    }
     
}

PersonSearch.Context.cs
//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
 
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
 
namespace LicenseVerification.Models
{
    public partial class be_cactusEntities : DbContext
    {
        public be_cactusEntities()
            base("name=be_cactusEntities")
        {
        }
     
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }
     
        public DbSet<tc_assignment> tc_assignment { getset; }
        public DbSet<tc_experience> tc_experience { getset; }
        public DbSet<tc_person> tc_person { getset; }
        public DbSet<tc_license> tc_license { getset; }
        public DbSet<tc_certificate> tc_certificate { getset; }
        public DbSet<tc_endorsement> tc_endorsement { getset; }
        public DbSet<tcc_license_level> tcc_license_level { getset; }
        public DbSet<tcc_license_status> tcc_license_status { getset; }
        public DbSet<tcc_qualified_by> tcc_qualified_by { getset; }
    }
}

5 Answers, 1 is accepted

Sort by
0
Samuel
Top achievements
Rank 2
answered on 03 Sep 2012, 03:35 AM
After going through a couple of pages of the forums, I came upon a suggestion to make sure you have the most up-to-date version of Kendo. Since I'm currently on the trial version (until the company agrees to pick up the tab) I downloaded the 30 day trial again and overwrote the files in the project then rebuilt. It eliminated all the issues EXCEPT grouping.

The only thing I've changed is the view. When I drag either "First Name" or "Last Name" to the bar, I get the little cross (image attached).

@model IEnumerable<LicenseVerification.Models.tc_person>
 
<h2> Without Partial</h2>
 
@{
    string viewLastName = "NULL";
    string viewFirstName = "NULL";
    if (ViewBag.lastName != null)
    {
        viewLastName = ViewBag.lastName;
    }
    if (ViewBag.firstName != null)
    {
        viewFirstName = ViewBag.firstName;
    }
         
}
@(Html.Kendo().Grid(Model)
        .Name("Grid")
        .Columns(cols =>
        {
            cols.Bound(p => p.person_id).Groupable(false);
            cols.Bound(p => p.first_name).Groupable(true);
            cols.Bound(p => p.last_name).Groupable(true);
        })
        .DataSource(ds => ds.Server()
                    .Read(read => read.Action("SearchResults", "PersonSearch", new { lastName = viewLastName, firstName = viewFirstName })))
        .Pageable(pageable => pageable.PageSizes(true).PageSizes(new int[] { 10, 25 }))
        .Sortable()
        .Groupable()
)
 
<p />
lastName is @viewLastName<br />
firstName is @viewFirstName
0
Petur Subev
Telerik team
answered on 05 Sep 2012, 02:55 PM
Hi Samuel,

As I replied in the support ticket you have opened, could you check if the jQuery version you are using is 1.8.0+ ? 

Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Samuel
Top achievements
Rank 2
answered on 05 Sep 2012, 03:40 PM
Yes, I updated the jQuery from 1.5 to 1.8 using Nuget. My _Layout is below:

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/styles/kendo.common.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/styles/kendo.default.min.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.8.0.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-2.5.3.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/KendoUI/js/kendo.all.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/KendoUI/js/kendo.aspnetmvc.min.js")" type="text/javascript"></script>

I've downloaded jquery-1.7.1.min.js from jQuery's website and that fixed the grouping issue - thank you so much!

With the model I posted, how would I go about accessing the district_id in the tc_experience collection? I'm relatively new to C# and lambda expressions are still difficult for me to understand, to the point where I've also been trying to get AutoMapper to create a ViewModel to make some of this a bit more understandable (and enforce the SoC) but can't figure out how to get at the district_id that is in the IEnumerable<tc_person> object I'm passing.
0
PAUL
Top achievements
Rank 1
answered on 11 Sep 2012, 07:32 PM
Hey I had the same problem and you probably have three kendo scripts in your Sitelayout and they are

 @* kendo scripts*@
    <script src="@Url.Content("~/Scripts/kendo.web.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/kendo.aspnetmvc.min.js")" type="text/javascript"></script>
   @* <script src="@Url.Content("~/Scripts/kendo.all.min.js")" type="text/javascript"></script>*@

As you can see the third one is commented out. We put in a ticket and tried everything. Took us couple of days to find out this was the problem...

Hope this helps
   
0
Samuel
Top achievements
Rank 2
answered on 11 Sep 2012, 07:38 PM
it turned out to be a combination of problems. I had upgraded to jQuery 1.8 and Kendo is only supported up to 1.7.1, and I had one too many scripts that were conflicting. Changed those things and the grouping, sorting, etc worked great! I also found that currently Kendo's grid won't support binding a column to a collection property so I'm trying to get a ViewModel working properly to act as a transition layer. Except for some LINQ issues (no good way to do a subselect), it's going well!
Tags
Grid
Asked by
Samuel
Top achievements
Rank 2
Answers by
Samuel
Top achievements
Rank 2
Petur Subev
Telerik team
PAUL
Top achievements
Rank 1
Share this question
or