小编Nei*_*ges的帖子

Lambda或Linq方法搜索多个参数

我有一个Of Of Of List和id,想查询带有多个参数的列表,以减少搜索页面上的结果.

     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);
        }
Run Code Online (Sandbox Code Playgroud)

搜索参数可能是'0',因为没有从上一页中选择,所以结果应该反映他的.

这是我传递的查询字符串:

Default.aspx?section=search&Sector=4&Location=0&Industry=0&Vacancy=0&SearchTerm= …

c# linq lambda

2
推荐指数
1
解决办法
7630
查看次数

标签 统计

c# ×1

lambda ×1

linq ×1