// GET: PostsManager public ActionResult Index(string searchString) { if (Session["MGID"] != null) { var post = postsManager.GetAllPosts(); if (!String.IsNullOrEmpty(searchString)) { post = post.Where(s => s.PTitle.Contains(searchString)); } var posts = db.Posts.Include(p => p.PostsComment).Include(p => p.Users).Include(p => p.Video); return(View(posts.ToList())); } else { return(RedirectToAction("ManagerLogin", "Manager")); } }
// GET: News public ActionResult Index(int?page, string searchString) { var posts = postsManager.GetAllPosts(); if (!String.IsNullOrEmpty(searchString)) { posts = posts.Where(s => s.PTitle.Contains(searchString)); } //第几页 int pageNumber = page ?? 1; //每页显示多少条 int pageSize = 10; //通过ToPagedList扩展方法进行分页 IPagedList <Posts> pagedList = posts.ToPagedList(pageNumber, pageSize); //将分页处理后的列表传给View return(View(pagedList)); }
public async Task <IHttpActionResult> GetAllPosts() { var data = await _postsManager.GetAllPosts(); return(Ok(data)); }