1. 程式人生 > >多條件查詢判斷

多條件查詢判斷

name inf public del turn white pty urn lis

/// <summary>
/// 查詢條件
/// </summary>
/// <param name="name"></param>
/// <param name="xiaoqu"></param>
/// <param name="donghao"></param>
/// <param name="huxing"></param>
/// <param name="zhuangtai"></param>
/// <returns></returns>
public ActionResult Select(string name = "", string xiaoqu = "", string donghao = "", string huxing = "", string zhuangtai = "")
{
XiaoQu();
DongHao();
HuXing();
ZhuangTai();
string where = "";
if (!string.IsNullOrWhiteSpace(name))
{
where += "a.ZuoLuo like ‘%" + name + "%‘";
}

if (!string.IsNullOrEmpty(xiaoqu))
{
where += "and a.XiaoQuID = " + xiaoqu + "";
}

if (!string.IsNullOrWhiteSpace(donghao))
{
where += "and a.DongHao = " + donghao + "";
}

if (!string.IsNullOrWhiteSpace(huxing))
{
where += "and a.HuXingID = " + huxing + "";
}

if (!string.IsNullOrWhiteSpace(zhuangtai))
{
where += "and a.ZhuangTaiID = " + zhuangtai + "";
}
Where = where;
List<UserInfoModel> list = ShowPage();
return View("Index", list);

}

多條件查詢判斷