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}) %>
    <%} %>

    添加一个样式表

  • 相关阅读:
    UIButton组件
    九宫格
    window对象的创建
    UILabel的属性及方法
    javascript相关,格式转化
    MySQL分区分表相关知识摘要
    redis简单笔记
    PHP常用设计模式
    在nginx上面部署多个项目
    把自己的项目上传到svn上面
  • 原文地址:https://www.cnblogs.com/poli/p/4351885.html
Copyright © 2011-2022 走看看