private ModelPagerArticle GetData(string Category = null, string CategoryTwo = null, string KeyWord = null, string PagerIndex = "1", string PagerSize = "30") { var model = new ModelPagerArticle(); model.PagerCount = 0; model.PagerIndex = 1; var pageIndex = 0; var pageSize = 0; int.TryParse(PagerIndex, out pageIndex); int.TryParse(PagerSize, out pageSize); var rowCount = decimal.Zero; var result = string.Empty; LogicArticle artDal = new LogicArticle(); CriteriaArticle.Pager criteria = new CriteriaArticle.Pager(); criteria.CategoryId = string.IsNullOrWhiteSpace(Category) ? null : Category; criteria.CategoryTwo = string.IsNullOrWhiteSpace(CategoryTwo) ? null : CategoryTwo; criteria.KeyWord = string.IsNullOrWhiteSpace(KeyWord) ? null : KeyWord; criteria.AuthorizeInfo = base.AuthorizeInfo; var list = artDal.QueryArticleListPager(out result, out rowCount, criteria, pageSize: pageSize, pageIndex: pageIndex); model.ArtcleList = list; model.PagerCount = pageSize == 0 ? 0 : Math.Ceiling(rowCount / pageSize); model.PagerIndex = pageIndex; model.Category = Category; model.CategoryTwo = CategoryTwo; model.KeyWord = KeyWord; if (list.Count > 0) { ViewBag.KeyWord = string.IsNullOrWhiteSpace(KeyWord) ? list.First().CategoryName : KeyWord; } return model; }
public ActionResult Index(string Category, string CategoryTwo, string KeyWord, string PagerIndex, string PagerSize) { var pageIndex = 0; var pageSize = 0; int.TryParse(PagerIndex, out pageIndex); int.TryParse(PagerSize, out pageSize); var customScript = string.Empty; IList<SelectListItem> categorys = new List<SelectListItem>(); IList<SelectListItem> categorysTwo = new List<SelectListItem>(); var rowCount = decimal.Zero; var resultMsg = string.Empty; var model = new ModelPagerArticle(); try { categorys = base.QueryCategoryAll(model.Category); categorysTwo = base.QueryCategoryAll(model.CategoryTwo); LogicArticle artDal = new LogicArticle(); CriteriaArticle.Pager criteria = new CriteriaArticle.Pager(); criteria.CategoryId = string.IsNullOrWhiteSpace(Category) ? null : Category; criteria.CategoryTwo = string.IsNullOrWhiteSpace(CategoryTwo) ? null : CategoryTwo; criteria.KeyWord = string.IsNullOrWhiteSpace(KeyWord) ? null : KeyWord; criteria.AuthorizeInfo = base.AuthorizeInfo; var list = artDal.QueryArticleListPager(out resultMsg, out rowCount, criteria, pageSize: pageSize, pageIndex: pageIndex); model.ArtcleList = list; model.PagerCount = pageSize == 0 ? 0 : Math.Ceiling(rowCount / pageSize); model.PagerIndex = pageIndex; } catch (AuthorizeException ex) { customScript = Library.Common.UtilityScript.ShowMessage("系统出错,错误信息:" + ex.Message, title: "警告", isSuccess: false, funName: "GotoLogin"); } catch (Exception ex) { customScript = Library.Common.UtilityScript.ShowMessage("系统出错,错误信息:" + ex.Message, title: "警告"); } ViewBag.CustomScript = customScript; ViewBag.Categorys = categorys; ViewBag.CategorysTwo = categorysTwo; return View(model); }