您好我需要2个选择列表和1个搜索字段,以便在索引视图中过滤数据。
我有来自MVC4的这个代码,有1个下拉列表和1个搜索功能,但我不能让它再用一个下拉列表。
你能帮助我朝正确的方向发展吗?
public ActionResult SearchIndex(string ChainSupplier, string searchString, string city)
{
var SupplierLst = new List<string>();
var SupplierQry = from d in db.DAT_SupplyChains
orderby d.Supplier
select d.Supplier;
SupplierLst.AddRange(SupplierQry.Distinct());
ViewBag.ChainSupplier = new SelectList(SupplierLst);
var cityLst = new List<string>();
var cityQry = from d in db.SUP_Cities
orderby d.Name
select d.Name;
cityLst.AddRange(cityQry.Distinct());
ViewBag.city = new SelectList(cityLst);
var Supplys = from m in db.DAT_SupplyChains
select m;
if (!String.IsNullOrEmpty(searchString))
{
Supplys = Supplys.Where(s => s.CompanyName.Contains(searchString));
}
if (!String.IsNullOrEmpty(ChainSupplier))
{
Supplys = Supplys.Where(x => x.Supplier == ChainSupplier);
return View(Supplys);
}
else
{
return View(Supplys.Where(x => x.SUP_City.Name == city));
}
问候和交换
贝
答案 0 :(得分:0)
if (!String.IsNullOrEmpty(searchString))
{
Supplys = Supplys.Where(s => s.CompanyName.Contains(searchString));
}
if (!String.IsNullOrEmpty(ChainSupplier))
{
Supplys = Supplys.Where(x => x.Supplier == ChainSupplier);
}
if (!String.IsNullOrEmpty(city))
{
return View(Supplys.Where(x => x.SUP_City.Name == city));
}
return View(Supplys);
}