public ActionResult ProductList(vProductListVM vm) { var query = db.Product.AsQueryable(); if (!string.IsNullOrWhiteSpace(vm.searchParameter.productName)) { query = query.Where( x => x.pName.Contains(vm.searchParameter.productName)); } int sId; if (!string.IsNullOrWhiteSpace(vm.searchParameter.style) && int.TryParse(vm.searchParameter.style, out sId)) { query = query.Where(x => x.sId == sId); } query = query.OrderBy(x => x.pId); int pageIndex = vm.pageIndex < 1 ? 1 : vm.pageIndex; var resualt = new vProductListVM { //ordernum=(int)Session[CDictionary.TK_Cart_Qty], searchParameter = vm.searchParameter, pageIndex = vm.pageIndex < 1 ? 1 : vm.pageIndex, styleItems = new SelectList(styles, "sId", "style"), products = query.ToPagedList(pageIndex, pageSize) }; return(View(resualt)); }
public ActionResult ProductList(int page = 1) { var query = db.Product.OrderBy(x => x.pId); int pageIndex = page < 1 ? 1 : page; var vm = new vProductListVM { searchParameter = new ProductSearchModel(), pageIndex = pageIndex, styleItems = new SelectList(this.styles, "sId", "style"), products = query.ToPagedList(pageIndex, pageSize) }; return(View(vm)); }