2015-07-28 74 views
1

我正在研究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 對不起,遲到:) –

回答

1

你必須做條件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

相關問題