Question on design of current pagination implementations
Posted
by
Freshblood
on Programmers
See other posts from Programmers
or by Freshblood
Published on 2011-06-12T09:53:09Z
Indexed on
2012/03/24
5:39 UTC
Read the original article
Hit count: 416
I have checked pagination implementations on asp.net mvc specifically and i really feel that there is something less efficient in implementations.
First of all all implementations use pagination values like below.
public ActionResult MostPopulars(int pageIndex,int pageSize)
{
}
The thing that i feel wrong is pageIndex and pageSize totally should be member of Pagination class otherwise this way looks so much functional way. Also it simplify unnecesary paramater pass in tiers of application.
Second thing is that they use below interface.
public interface IPagedList<T> : IList<T>
{
int PageCount { get; }
int TotalItemCount { get; }
int PageIndex { get; }
int PageNumber { get; }
int PageSize { get; }
bool HasPreviousPage { get; }
bool HasNextPage { get; }
bool IsFirstPage { get; }
bool IsLastPage { get; }
}
If i want to routing my pagination to different action so i have to create new view model for encapsulate action name in it or even controller name. Another solution can be that sending this interfaced model to view then specify action and controller hard coded in pager method as parameter but i am losing totally re-usability of my view because it is strictly depends on just one action.
Another thing is that they use below code in view
Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount)
If the model is IPagedList why they don't provide an overload method like @Html.Pager(Model)
or even better one is @Html.Pager()
. You know that we know model type in this way. Before i was doing mistake because i was using Model.PageIndex instead of Model.PageNumber.
Another big issue is they strongly rely on IQueryable interface. How they know that i use IQueryable in my data layer ? I would expected that they work simply with collections that is keep pagination implementation persistence ignorant.
What is wrong about my improvement ideas over their pagination implementations ? What is their reason to not implement their paginations in this way ?
© Programmers or respective owner