public async Task <ActionResult> GetSearch(string searchWord, int searchType = 0, int pageIndex = 1, int pageSize = 10) {//searchType:0-查用户名和标题 1-查标题 2-查用户名 if (searchWord == "") { return(Json(new { status = "fail", result = "搜索关键字为空" }, JsonRequestBehavior.AllowGet));;//返回错误页面 } IArticleManager articleManager = new ArticleManager(); List <ArticleDto> data = await articleManager.GetAllSearchArticles(searchWord, searchType, pageIndex - 1, pageSize); int dataCount = await articleManager.GetSearchArticleDataCount(searchWord, searchType); //符合搜索的文章总数 var pageCount = dataCount % pageSize == 0 ? dataCount / pageSize : dataCount / pageSize + 1; //总页数 return(Json(new { status = "ok", data, dataCount, pageCount, pageIndex, pageSize, searchWord, searchType }, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> Search(string searchWord, int searchType = 0, int pageIndex = 1, int pageSize = 10) {//searchType:0-查用户名和标题 1-查标题 2-查用户名 if (searchWord == "") { ViewBag.PageCount = 0; //总页数 ViewBag.PageIndex = pageIndex; //当前页数 ViewBag.SearchWord = searchWord; //当前关键字 ViewBag.SearchType = searchType; //当前类型 return(View(new List <ArticleDto>())); } IArticleManager articleManager = new ArticleManager(); List <ArticleDto> data = await articleManager.GetAllSearchArticles(searchWord, searchType, pageIndex - 1, pageSize); int dataCount = await articleManager.GetSearchArticleDataCount(searchWord, searchType); //符合搜索的文章总数 ViewBag.PageCount = dataCount % pageSize == 0 ? dataCount / pageSize : dataCount / pageSize + 1; //总页数 ViewBag.DataCount = dataCount; //匹配数量 ViewBag.PageIndex = pageIndex; //当前页数 ViewBag.SearchWord = searchWord; //当前关键字 ViewBag.SearchType = searchType; //当前查询类型 return(View(data)); }