zoukankan      html  css  js  c++  java
  • Mvc分页

    int pageIndex;
    int pageSize = 9;
    if(!int.TryParse(Request["pageIndex"],out pageIndex))
    {
    pageIndex = 1;
    }

            mvcDbEntities db = new mvcDbEntities();
            //总页数
            int totalCount = db.YongHu.Count();
            int pageCount = Convert.ToInt32(Math.Ceiling(totalCount * 1.0 / pageSize));
            if (pageIndex < 1)
            {
                pageIndex = 1;
            }
            if(pageIndex>pageCount)
            {
                pageIndex = pageCount;
            }
            var yonghuList = db.YongHu.Where<YongHu>(c => true).OrderBy<YongHu, int>(c => c.YongHuId).Skip<YongHu>((pageIndex - 1) * pageSize).Take<YongHu>(pageSize);
            List<YongHu> list = yonghuList.ToList();
            ViewData.Model = list;
            ViewBag.PageIndex = pageIndex;
            ViewBag.PageSize = pageSize;
            ViewBag.PageCount = pageCount;
            ViewBag.TotalCount = totalCount;
            return View();
    

    <%for(int i=1;i<=(int)ViewBag.PageCount;i++){ %>
    <%:Html.ActionLink(i.ToString(),"Index",new {pageIndex=i}) %>
    <%} %>

    添加一个样式表

  • 相关阅读:
    元组tuple
    列表list
    day11---闭包函数
    day10函数对象,嵌套,名称空间,作用域
    day10函数对象,嵌套,名称空间,作用域
    day--函数
    day8--文件管理2
    day ---7,文件管理
    day7,文件编码
    day6---字典,集合内置方法
  • 原文地址:https://www.cnblogs.com/poli/p/4351885.html
Copyright © 2011-2022 走看看