Asp.net mvc 4 在MVC中使用多个下拉列表进行过滤
我正在从事三层体系结构项目 我有多个下拉列表来过滤使用LINQ从数据库中获取的数据 现在我需要一种方法来过滤这些下拉列表,当我在任何下拉列表中选择一个项目时,它正在过滤,当我从两个下拉列表中选择时,根据这两个选择进行过滤,依此类推 我这样使用linq:Asp.net mvc 4 在MVC中使用多个下拉列表进行过滤,asp.net-mvc-4,drop-down-menu,linq-to-sql,Asp.net Mvc 4,Drop Down Menu,Linq To Sql,我正在从事三层体系结构项目 我有多个下拉列表来过滤使用LINQ从数据库中获取的数据 现在我需要一种方法来过滤这些下拉列表,当我在任何下拉列表中选择一个项目时,它正在过滤,当我从两个下拉列表中选择时,根据这两个选择进行过滤,依此类推 我这样使用linq: var doctors = from d in db.Doctors where d.CityID == id && d.HasSecretary == hasSec
var doctors = from d in db.Doctors
where d.CityID == id
&& d.HasSecretary == hasSec
&& d.OldSystem == oldSys
&& d.MetDoctor == metDoc
&& d.PriceProblem == priceProb
&& d.EasyToConvince == easyToCon
&& d.ComputerSavvy == comSav
&& d.Sold == sold
&& d.NotInterested == notIntr
&& d.FollowUp == followUp
&& d.NewClinic == newClin
&& d.RequestedADemo == reqDemo
select d;
它只在我选择所有下拉列表时才过滤,而不是单独过滤
请帮助:)您必须执行条件where子句,例如
var doctors = from d in db.Doctors;
if (id != null)
doctors = doctors.Where(d => d.CityID == id);
if (hasSec)
doctors = doctors.Where(d => d.HasSecretary == hasSec);
// other if statements
// results
var results = doctors.ToList();
你最终找到解决办法了吗?是的,谢谢你,很抱歉迟到:)@IbrahimSamara没问题。