码迷,mamicode.com
首页 > Web开发 > 详细

MVC Pager使用

时间:2016-07-04 18:39:45      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:

View中加入引用:@using Webdiyer.WebControls.Mvc;

使用时代码:

<div id="Pagination">
                @Html.Pager(Model.DataList, new PagerOptions
 {
     PageIndexParameterName = "PageIndex",
     ShowPrevNext = true,
     FirstPageText = "首页",
     PrevPageText = "上一页",
     NextPageText = "下一页",
     LastPageText = "末页",
     HorizontalAlign="right",
     PagerItemTemplate=" {0}"
 })
            </div>

  

后台Controller:

public ActionResult NewsList(int tid = 1, int PageIndex = 1)
        {
            int PageSize = 10;
            int RecordCount = db.ArticlesInfos.Count();
            int PageCount = (RecordCount / PageSize) + (RecordCount % PageSize > 0 ? 1 : 0);

            ViewData["Tid"] = tid;

            PagedList<Models.ArticlesInfo> list = db.ArticlesInfos.OrderByDescending(c => c.ID).AsQueryable().ToPagedList(PageIndex, PageSize);
            ViewModel.MVCPagerModel<Models.ArticlesInfo> model = new ViewModel.MVCPagerModel<Models.ArticlesInfo>();
            model.PageCount = PageCount;
            model.RecordCount = RecordCount;
            model.PageSize = PageSize;
            model.PageIndex = PageIndex;
            model.DataList = list;
            return View(model);
        }

 

分页类:

public class VMNewsListPage<T>
    {
        public int PageIndex { get; set; }
        public int PageCount { get; set; }
        public int RecordCount { get; set; }
        public int PageSize { get; set; }
        public PagedList<T> ArticlesInfos { get; set; }
    }

 

demo:

@{
    ViewBag.Title = "NewsList";
    Layout = "~/Views/Shared/_LayoutPageOne.cshtml";

}

@model MvcApplication1.ViewModel.MVCPagerModel<MvcApplication1.Models.ArticlesInfo>
@using Webdiyer.WebControls.Mvc;

@section header{

}

<div class="pageban" style="background-image: url(/images/20141002091135849.jpg);"></div>
<div class="Contain">
    <!--/*内容*/-->
    <div class="Left">
        <div class="Sidebar">
            <div class="title">新闻动态</div>
            <ul class="sub">
                <li><a href="NewsList?tid=1&PageIndex=1" id="a_group_1" class="@(Convert.ToInt32(ViewData["Tid"]) == 1 ? "aon" : "")">公司新闻</a></li>
                <li><a href="NewsList?tid=2&PageIndex=1" id="a_group_2" class="@(Convert.ToInt32(ViewData["Tid"]) == 2 ? "aon" : "")">行业动态</a></li>
            </ul>
            @Html.Partial("UCLeftContact")
        </div>
        <!--/*正文*/-->
        <div class="Main">

            <div class="Current">
                <em>
                    您在这里:

                    <a href="Index">首页</a>
                    >
                    <a href="NewsList?tid=@ViewData["Tid"]&PageIndex=1" id="a_group_nav_1">新闻动态</a> > <a href="NewsList?tid=@ViewData["Tid"]&PageIndex=1" id="a_group_nav_2">@(Convert.ToInt32(ViewData["Tid"]) == 1 ? "公司新闻" : "行业动态")</a> >
                </em>
                <b id="a_group_nav_3">@(Convert.ToInt32(ViewData["Tid"]) == 1 ? "公司新闻" : "行业动态")</b>
            </div>
            <!--/*新闻列表*/-->
            <dl class="Newlist">

                @foreach (var item in Model.DataList)
                {
                    <dd>
                        <div class="pic">
                            <a href="NewsDetail?id=@item.ID" target="_blank" title="@item.Title">
                                <img src="@item.Img" alt="@item.Title">
                            </a>
                        </div>
                        <div class="text">
                            <h1>
                                <span>@item.CreateDate.ToString("yyyy-MM-dd")</span>
                                <a href="NewsDetail?id=@item.ID" target="_blank" style="">@item.Title</a>
                            </h1>
                            <p>@(Framework.Common.Utils.GetHtml(HttpUtility.HtmlDecode(item.Contents), 60))...</p>
                            <a href="NewsDetail?id=@item.ID" target="_blank" class="detail">详细>></a>
                        </div>
                    </dd>
                }

            </dl>
            <!--/*pages*/-->
            <div id="Pagination">
                @Html.Pager(Model.DataList, new PagerOptions
           {
               PageIndexParameterName = "PageIndex",
               ShowPrevNext = true,
               FirstPageText = "首页",
               PrevPageText = "上一页",
               NextPageText = "下一页",
               LastPageText = "末页",
               HorizontalAlign = "right",
               PagerItemTemplate = " {0}"
           })
            </div>
            <!--/*新闻列表end */-->
        </div>

        <div class="clear"></div>
    </div>
    @Html.Partial("UCDetailsRight")
    <div class="clear"></div>
    <!--/*内容 end*/-->
</div>

  

参考:http://www.webdiyer.com/mvcpager/

MVC Pager使用

标签:

原文地址:http://www.cnblogs.com/xsj1989/p/5641124.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!