재우니의 블로그



https://github.com/ernado-x/X.PagedList



Troy's 프로젝트에도 PagedList (https://github.com/troygoode/PagedList) 를 제공하고 있는데, 여기에 있는 프로젝트인 X.PagedList 과 차이점은 X.PagedList 경우 portable 어셈블리라는 점이 다르다는 것입니다.


그게 무슨 의미냐면, 이전것은 web projects 에서만 사용이 가능했지만,이젠 winforms,windows phone, sliverlight 기타에 사용될 수 있다는 것을 의미합니다.


PagedList 은 IEnumerable/IQueryable 을 쉽게 가져다가 사용할 수 있는 라이브러리 입니다. PagedList.Mvc 의 역할은 이전, 다음같은 링크를 가져다주는 pager control 을 보여주고 “page”에 가져다 주게끔 하는 역할을 합니다.


 

설치 방법은 nuget 에서 X.PagedList.Mvc 로 visual studio 에서 검색하여 설치하면 됩니다. 나머지는 사용방법인데,


 

How do I use it?

    Install "X.PagedList.Mvc" via NuGet - that will automatically install "X.PagedList" as well.

    In your controller code, call ToPagedList off of your IEnumerable/IQueryable passing in the page size and which page you want to view.

    Pass the result of ToPagedList to your view where you can enumerate over it - its still an IEnumerable, but only contains a subset of the original data.

    Call Html.PagedListPager, passing in the instance of the PagedList and a function that will generate URLs for each page to see a paging control.

 

https://github.com/ernado-x/X.PagedList 해당 사이트가서 download zip 하여 다운로드받고 소스 분석하면 쉽게 이해하실 수 있을겁니다. 또한 샘플예제 설명도 되어 있으니 이해하시는데 어려움이 없을 겁니다. IEnumerable/IQueryable 로 인해 model 을 만들어서 view 에서 @model 구문을 통해 참조할 필요 없다는 점이 좋네요.



단, view 단에서 아래 핼퍼를 using 문으로 참조해야 합니다.



@using PagedList.Mvc; //import this so we get our HTML Helper
@using PagedList; //import this so we can cast our list to IPagedList (only necessary because ViewBag is dynamic)