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
PersonSearchController.cs
SearchResults.cshtml
My model is from a DBContext template and Entity Framework, but it is below in case it's relevant:
tc_person.cs
PersonSearch.Context.cs
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 =
""
,
string
lastName =
""
)
{
return
View(GetEducators(firstName,lastName));
}
private
IEnumerable GetEducators(
string
firstName =
""
,
string
lastName =
""
)
{
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 {
get
;
set
; }
public
System.DateTime date_record_added {
get
;
set
; }
public
string
prefix {
get
;
set
; }
public
string
last_name {
get
;
set
; }
public
string
first_name {
get
;
set
; }
public
string
middle_name {
get
;
set
; }
public
string
suffix {
get
;
set
; }
public
string
preferred_name {
get
;
set
; }
public
string
maiden_name {
get
;
set
; }
public
string
aka {
get
;
set
; }
public
string
ethnic_code {
get
;
set
; }
public
string
gender {
get
;
set
; }
public
Nullable<System.DateTime> dob {
get
;
set
; }
public
Nullable<System.DateTime> deceased_date {
get
;
set
; }
public
string
citizenship {
get
;
set
; }
public
string
nclb_veteran {
get
;
set
; }
public
Nullable<System.DateTime> ethics_test {
get
;
set
; }
public
virtual
ICollection<tc_experience> tc_experience {
get
;
set
; }
public
virtual
ICollection<tc_license> tc_license {
get
;
set
; }
public
virtual
ICollection<tc_certificate> tc_certificate {
get
;
set
; }
}
}
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 {
get
;
set
; }
public
DbSet<tc_experience> tc_experience {
get
;
set
; }
public
DbSet<tc_person> tc_person {
get
;
set
; }
public
DbSet<tc_license> tc_license {
get
;
set
; }
public
DbSet<tc_certificate> tc_certificate {
get
;
set
; }
public
DbSet<tc_endorsement> tc_endorsement {
get
;
set
; }
public
DbSet<tcc_license_level> tcc_license_level {
get
;
set
; }
public
DbSet<tcc_license_status> tcc_license_status {
get
;
set
; }
public
DbSet<tcc_qualified_by> tcc_qualified_by {
get
;
set
; }
}
}