MvcContrib Pager Styling
Is it possible to style the MvcContrib Grid pager to just show "1 2 3 4 ..." for pagi开发者_JAVA百科ng?
As far as I can tell, that option doesn't exist out of the box. I asked the same question on the codeplex but it seems to be not ready yet:
http://mvccontrib.codeplex.com/workitem/5745
There is my implementation of such feature:
@using MvcContrib.UI.Pager
@model MvcContrib.Pagination.IPagination
@{
string action = ViewContext.Controller.ValueProvider.GetValue("action").RawValue.ToString();
string controller = ViewContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString();
}
@functions
{
public RouteValueDictionary GetRoute(int page)
{
var routeValues = new RouteValueDictionary();
foreach (var key in Context.Request.QueryString.AllKeys.Where(key => key != null))
{
routeValues[key] = Context.Request.QueryString[key];
}
routeValues["page"] = page;
return routeValues;
}
}
<div class="pagination">
<center>
<span class="paginationRight">
@{
int thisPage = Model.PageNumber;
if (Model.HasPreviousPage)
{
for (int i = (5 < Model.PageNumber ? 5 : Model.PageNumber); i >= 1; i--)
{
int page = thisPage - i;
if (page > 0)
{
<text>
@Html.ActionLink(page.ToString(), action, controller, GetRoute(page), null)
</text>
}
}
}
<text> | @Model.PageNumber | </text>
if (Model.HasNextPage)
{
for (int i = 1; i <= (5 < Model.TotalPages - Model.PageNumber ? 5 : Model.TotalPages - Model.PageNumber); i++)
{
int page = thisPage + i;
if (page > 0)
{
<text>
@Html.ActionLink(page.ToString(), action, controller, GetRoute(page), null)
</text>
}
}
}
}
</span>
</center>
</div>
It is not beautifull or anything, but it works quite fine for me, and is very simple to modify it to your needs.
精彩评论