学习ASP.NET,我有一个基本表(SQL数据库),其中包含我想要使用下拉菜单过滤的数据。我也已经实现了一个基本的搜索功能,我希望这两个功能一起工作。 现在,下拉列表什么也没做。它看到正确的值,但选择一个值什么都不做。
这是我的控制器:(我包含了所有代码的部分内容)
public ActionResult Index(string sortOrder, string currentFilter, string searchString, int? page, string AddressFilter)
{
//Sorting parameters
ViewBag.LastNameSortParm = String.IsNullOrEmpty(sortOrder) ? "eLastName_desc" : ""; ......
var dbEmployee = db.Employee.AsEnumerable().OrderBy(s => s.eLastName, StringComparer.CurrentCulture);
var employee = from s in dbEmployee select s;
//Search
if (searchString == null)
{ ........
ViewBag.CurrentFilter = searchString;
//Search functionality
if (!String.IsNullOrEmpty(searchString))
{
employee = employee.Where(s =>
s.eLastName.ToUpper().Contains(searchString.ToUpper()) || ......
这是下拉列表的代码。
//Filter for dropdown, Address
ViewBag.AddressFilter = (from s in db.Employee
select s.eAddress).Distinct();
if (!String.IsNullOrEmpty(AddressFilter))
{
employee = employee.Where(s => s.eAddress.ToUpper().Contains(AddressFilter.ToUpper()));
}
int pageSize = 5;
int pageNumber = (page ?? 1);
return View(employee.ToPagedList(pageNumber, pageSize));
}
我的视图看起来像这样:
@using (Html.BeginForm())
{
<p>Search here: @Html.TextBox("SearchString")
<input type="submit" value="Search"/></p>
}
<p>
@Html.ActionLink("Create New", "Create")
</p>
<p>Department</p>@Html.DropDownList("Department", new
SelectList(ViewBag.AddressFilter))
<table class="table">
<tr>
<th>
@Html.ActionLink("eFirstName", "Index", new { sortOrder =
ViewBag.FirstNameSortParm, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
@Html.ActionLink("eLastName", "Index", new { sortOrder =
ViewBag.LastNameSortParm, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
@Html.ActionLink("eAddress", "Index", new { sortOrder =
ViewBag.AddressSortParm, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
@Html.ActionLink("eSalary", "Index", new { sortOrder = ViewBag.SalarySortParm, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
@Html.ActionLink("Department", "Index", new { sortOrder = ViewBag.DepartmentSortParm, currentFilter = ViewBag.CurrentFilter })
</th>
<th></th>
</tr>
所以我显然错过了一些东西而且我无法找到答案。 (旁注,地址只是城市,但我还没有更改名称)。 感谢您提出任何建议或指示