public virtual ActionResult Query(String query) { var expression = LambdaHelper.BuildLambdasOr <T>("Code,Name", QueryMethods.Contains, query); IEnumerable <T> list = model.GetList(expression); return(Json(new SuccessActionResult("ok", list))); }
/// <summary> /// 首次加载、列表操作、翻页、排序、刷新、搜索查询、Ajax请求树 /// </summary> /// <param name="pagingModel"></param> /// <returns></returns> public override ActionResult Index([ModelBinder(typeof(PagingModelBinder))] PagingModel pagingModel) { var type = Request.Params["type"]; Response.Cache.SetOmitVaryStar(true); SelectProductsViewModel pvm = new SelectProductsViewModel(); ViewBag.Sort = pagingModel.SortOptions; var parentId = Request.Params["parentId"]; var parentCode = Request.Params["parentCode"]; Category categoryModel = new Category(); if (String.IsNullOrWhiteSpace(parentId)) { pvm.CategoriesTree = categoryModel.GetList(p => p.ParentId == null); } var expr = LambdaHelper.BuildLambdasOr <Product>(pagingModel.QueryFields, QueryMethods.Contains, pagingModel.Query); if (String.IsNullOrWhiteSpace(parentCode)) { pvm.ProductsList = model.GetPagedList(pagingModel, expr); } else { var predicate = PredicateBuilder.True <Product>(); switch (type) { case "Brands": predicate = predicate.And(f => f.Brand.Code.StartsWith(parentCode)).And(expr); break; case "Categories": predicate = predicate.And(f => f.Category.Code.StartsWith(parentCode)).And(expr); break; default: predicate = predicate.And(f => f.Category.Code.StartsWith(parentCode)).And(expr); break; } pvm.ProductsList = model.GetPagedList(pagingModel, predicate); } if (Request.IsAjaxRequest()) { if (Request.HttpMethod == "GET") { return(PartialView("_Index", pvm)); } else { return(Json(new SuccessActionResult("Ok", pvm.CategoriesTree))); } } return(View("Index", pvm)); }
/// <summary> /// 首次加载、列表操作、翻页、排序、刷新、搜索查询、Ajax请求树 /// </summary> /// <param name="pagingModel"></param> /// <returns></returns> public override ActionResult Index([ModelBinder(typeof(PagingModelBinder))] PagingModel pagingModel) { CategoriesViewModel cvm = new CategoriesViewModel(); ViewBag.Sort = pagingModel.SortOptions; var parentId = Request.Params["parentId"]; var parentCode = Request.Params["parentCode"]; if (String.IsNullOrWhiteSpace(parentId)) { cvm.CategoriesTree = model.GetList(p => p.ParentId == null); } else { Int32 pId = Int32.Parse(parentId); cvm.CategoriesTree = model.GetList(p => p.ParentId == pId); } var expr = LambdaHelper.BuildLambdasOr <Category>(pagingModel.QueryFields, QueryMethods.Contains, pagingModel.Query); if (String.IsNullOrWhiteSpace(parentCode)) { cvm.CategoriesList = model.GetPagedList(pagingModel, expr); } else { var predicate = PredicateBuilder.True <Category>(); predicate = predicate.And(f => f.Code.StartsWith(parentCode)).And(expr); cvm.CategoriesList = model.GetPagedList(pagingModel, predicate); } if (Request.IsAjaxRequest()) { if (Request.HttpMethod == "GET") { return(PartialView("_Index", cvm)); } else { return(Json(new SuccessActionResult("Ok", cvm.CategoriesTree))); } } return(View("Index", cvm)); }
public override ActionResult Query([ModelBinder(typeof(PagingModelBinder))] PagingModel pagingModel) { Response.Cache.SetOmitVaryStar(true); SelectProductsViewModel pvm = new SelectProductsViewModel(); Category categoryModel = new Category(); ViewBag.Sort = pagingModel.SortOptions; ViewBag.Query = pagingModel.Query; pagingModel.PageSize = 10; var parentId = Request.Params["parentId"]; var parentCode = Request.Params["parentCode"]; if (String.IsNullOrWhiteSpace(parentId)) { pvm.CategoriesTree = categoryModel.GetList(p => p.ParentId == null); } else { Int32 pId = Int32.Parse(parentId); pvm.CategoriesTree = categoryModel.GetList(p => p.ParentId == pId); } var expr = LambdaHelper.BuildLambdasOr <Product>(pagingModel.QueryFields, QueryMethods.Contains, pagingModel.Query); if (String.IsNullOrWhiteSpace(parentCode)) { pvm.ProductsList = model.GetPagedList(pagingModel, expr); } else { var predicate = PredicateBuilder.True <Product>(); predicate = predicate.And(f => f.Category.Code.StartsWith(parentCode)).And(expr); pvm.ProductsList = model.GetPagedList(pagingModel, predicate); } if (Request.HttpMethod == "GET") { return(PartialView("_Query", pvm)); } //默认是PUT return(PartialView("Query", pvm)); }