MVC Controller where lambda表达式拼接
[HttpPost]
public ActionResult Index(FormCollection form)
{
//0.接收参数 page=1&rows=5
int pageIndex = int.Parse(form["page"]);
int pageSize = int.Parse(form["rows"]);
string strWorkCode = form["WorkCode"];
string strName = form["Name"];
string strIMEI = form["IMEI"];
#region 拼接查询条件
Expression<Func<P_User, bool>> where = p => p.IsActive == true;
if (strWorkCode != null && strWorkCode.Length > 0)
{
where = where.And(r => r.WorkCode == strWorkCode);
}
if (strName != null && strName.Length > 0)
{
where = where.And(s => s.Name.Contains(strName));
}
//2016-11-29 zch
if (strIMEI != null && strIMEI.Length > 0)
{
where = where.And(s => s.IMEI.Contains(strIMEI));
}
#endregion
//1.读取数据
var rowCount = 0;
var list = new P_UserBLL().GetPagedList(pageIndex, pageSize, ref rowCount, where, u => u.ID, true).Select(u => u.ToExtModle());
//2.返回数据
return Json(new Model.EasyUIModel.DataGridModel() { total = rowCount, rows = list });
}

浙公网安备 33010602011771号