Asp.net Mvc使用PagedList分页

git:
https://github.com/troygoode/PagedList



1. Nuget 安装package

Asp.net Mvc使用PagedList分页_第1张图片


2.View


@{
    ViewBag.Title = "Processes Listing";
}
@using PagedList.Mvc; 
@using PagedList; 


<link href="/Content/PagedList.css" rel="stylesheet" type="text/css" />




<h2>List of Processes</h2>
<ul>
    @foreach(var process in ViewBag.Processes){
        <li>@process.ProcessName</li>
    }
</ul>




@Html.PagedListPager((IPagedList)ViewBag.Processes, page => Url.Action("Index", new { page }))



3.C#

public object Index(int? page)
        {
            var processes = System.Diagnostics.Process.GetProcesses();


            var pageNumber = page ?? 1; 
            var onePageOfProcesses = processes.ToPagedList(pageNumber, 25);


            ViewBag.Processes = onePageOfProcesses;
            return View();
        }


4. 运行


Asp.net Mvc使用PagedList分页_第2张图片

你可能感兴趣的:(asp.net)