我有一個列表的對象和id喜歡用多個參數查詢列表,以減少搜索結果的搜索頁面。Lambda或Linq方法來搜索多個參數
int SecLink = (!string.IsNullOrEmpty(Request.QueryString["Sector"])) ? Convert.ToInt32(Request.QueryString["Sector"]) : 0;
int LocLink = (!string.IsNullOrEmpty(Request.QueryString["Location"])) ? Convert.ToInt32(Request.QueryString["Location"]) : 0;
int IndLink = (!string.IsNullOrEmpty(Request.QueryString["Industry"])) ? Convert.ToInt32(Request.QueryString["Industry"]) : 0;
int VacLink = (!string.IsNullOrEmpty(Request.QueryString["Vacancy"])) ? Convert.ToInt32(Request.QueryString["Vacancy"]) : 0;
string keyword = Request.QueryString["SearchTerm"];
var dx = new DataX();
var lstJobs = dx.GetAllJobs().Where(x => x.SectorLink.Equals(SecLink) && x.LocationLink.Equals(LocLink) && x.IndustryLink.Equals(IndLink) && x.VacancyTypeLink.Equals(VacLink) && x.JobName.Contains(keyword)).ToList();
if (lstJobs.Count > 0)
{
uiRptSearchJobs.DataSource = lstJobs;
uiRptSearchJobs.DataBind();
uiLitSearchResults.Text = string.Format("<h4>Search result found {0} matches</h4>", lstJobs.Count);
}
由於沒有從上一頁中選擇搜索參數,所以搜索參數可能爲'0',所以結果應該反映他的。
這是查詢字符串IM傳:
Default.aspx?section=search&Sector=4&Location=0&Industry=0&Vacancy=0&SearchTerm=
,但你可以看到他們的查詢字符串將與哪些用戶從以前的頁面選擇更改。
不明白你的問題/問題。 – leppie
var lstJobs返回所有作業,即使LocationLink = 0,IndustryLink = 0但只有SectorLink = 4 –
@NeilHodges當然,它會返回** no **作業,因爲您將測試'LocationLink == 0',這可能從來都不是真的? –