shopEntities shop = new shopEntities(); public ActionResult Index() { //IQueryable<tbl_order> order = (from a in shop.tbl_order select a).OrderBy(a=>a.id).Skip(10).Take(10); //ViewData["order"] = order; //return View(); int pageIndex = Request["pageIndex"] == null ? 1 : int.Parse(Request["pageIndex"]); int pageSize = Request["pageSize"] == null ? 10 : int.Parse(Request["pageSize"]); int totalCount = 0; //给前台传递 分页的参数数据 ViewData["pageIndex"] = pageIndex; //ViewData["pageSize"] = pageSize; ViewBag.pageSize = pageSize; //总条数 totalCount = shop.tbl_order.Count(); ViewBag.totalCount = totalCount; //把当前页面数据发送到前台。 //ViewData.Model = db.UserInfo.ToList(); //List<tbl_order> pp = shop.tbl_order // .OrderBy(u => u.id) // .Skip((pageIndex - 1) * pageSize) // .Take(pageSize).ToList(); IQueryable<tbl_order> pp = shop.tbl_order .OrderBy(u => u.id) .Skip((pageIndex - 1) * pageSize) .Take(pageSize); return View(pp); }
asp.net MVC分页代码分享(2)
内容版权声明:除非注明,否则皆为本站原创文章。