在MVC中使用多个下拉列表进行过滤

问题描述:

我正在研究3层架构项目 ,我有多个DropDown列表可以过滤使用LINQ从数据库中获取的数据。在MVC中使用多个下拉列表进行过滤

现在我需要的方式与这些下拉菜单,其中,当我在它被过滤任何下拉列表中选择一个项目,然后过滤,当我从两个下拉列表中选择这两个选项来过滤等等...

我使用linq像这样:

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; 

而且它只在选择所有下拉列表时进行筛选,而不是单独进行筛选。

请帮忙:)

+0

您是否最终找到解决方案? – CrnaStena

+0

yess谢谢yooou 对不起,迟到:) –

你必须做条件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(); 
+0

感谢的人 它的工作 和对不起迟:) –

+0

@IbrahimSamara没有问题。 – CrnaStena