I need to provide two distinct filters in my MVC 5 application (one via text box control and the other via drop down list), which uses the Entity Framework. Having difficulty populating the control with selected values from the table. While I was initially worried about multiple values (in the list control) because I joined a table with multiple values into one with single items, I haven’t gotten beyond step 1. I should point out that I am using a paged list control, which may be complicating things more.
MODEL (Fairly straightforward with not much to see here)
CONTROLLER
Fairly straightforward with a sort and name filter
if (searchString != null)
{
page = 1;
}
else
{
searchString = currentFilter;
}
ViewBag.CurrentFilter = searchString;
var employees = from s in db.tblEmployeeADPs.Include(s => s.tblDepartmentFuncADP)
.Where(s => s.Status == "Active")
select s;
if (!String.IsNullOrEmpty(searchString))
{
employees = employees.Where(s => s.LastName.Contains(searchString)
|| s.FirstName.Contains(searchString));
}
if (!String.IsNullOrEmpty(DepartmentFunction))
{
employees = employees.Where(s => s.HomeDepartmentDesc == DepartmentFunction);
}
int pageSize = 30;
int pageNumber = (page ?? 1);
return View(employees.ToPagedList(pageNumber, pageSize));
VIEW
@using (Html.BeginForm("Index","Employee", FormMethod.Get))
{
<p>
Find by name: @Html.TextBox("searchString", ViewBag.currentFilter as String)
<input type="submit" value="Search" />
<img style="5px"/>
XMan-Filter: @Html.DropDownListFor(m => m.FunctionName, new SelectList(ViewBag.DepartmentFunc, "FunctionName", "FunctionNAme"), "-- Select One --")
</p>
}
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index",
new { sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter, page, PlaceHolderForVariable}))
When I attempt to use the m => m.valuename lambda syntax to test anything out of the collection, I get an error:
PagedList.IPagedList' does not contain a definition for 'FunctionName' and no extension method 'FunctionName' accepting a first argument of type 'PagedList.IPagedList' could