* PagedList.MVC [#e6f38f4a]

- https://github.com/TroyGoode/PagedList
- http://www.nuget.org/packages/PagedList.Mvc/


** Manual Paging [#x84f11d5]
*** Controller [#c2bbdb24]
 namespace WebApplication1.Controllers
 {
    public class HomeController : Controller
    {
        public ActionResult Index(int? page)
        {
            var pageIndex =( page ?? 1) - 1;
            var pageSize = 2;

 
            var dsn = "Server=hv-cent01;Port=5432;User Id=taro;Password=mypass;Database=mydb";
            var cn = new NpgsqlConnection(dsn);
            cn.Open();

 
            var count = (int) cn.Query<Int64>(@"SELECT COUNT(*) AS count FROM t1").Single();

 
            var rows = cn.Query<MyEntity>(@"SELECT * FROM t1 OFFSET @offset LIMIT @limit",
                new { offset = pageIndex * pageSize, limit = pageSize });
            var pagedList = new StaticPagedList<MyEntity>(rows, pageIndex + 1, pageSize, (int) count);
            ViewBag.Rows = pagedList;

 
            return View();
        }
    }
 }

*** View [#g831cf34]
 @{
     ViewBag.Title = "Index";
 }
 @using PagedList.Mvc;
 @using PagedList;
 
 <link href="~/Content/PagedList.css" rel="stylesheet" />
 
 <h1>@ViewBag.Title</h1>
 <ul>
     @foreach (var row in ViewBag.Rows)
     {
         <li>@row.Id @row.Name</li>
     }
 </ul>
 
 @Html.PagedListPager((IPagedList)ViewBag.rows, page => Url.Action("Index", new { page }))

- https://github.com/troygoode/pagedlist#example-2-manual-paging


トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS