0

是否可以将 MvcContrib Grid 寻呼机设置为仅显示“1 2 3 4 ...”进行寻呼?

4

2 回答 2

0

据我所知,该选项不存在开箱即用。我在 codeplex 上问了同样的问题,但似乎还没有准备好:

http://mvccontrib.codeplex.com/workitem/5745

于 2011-04-08T09:27:09.170 回答
0

我有这样的功能实现:

@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>

它并不漂亮或任何东西,但对我来说效果很好,并且很容易根据您的需要进行修改。

于 2012-07-05T17:37:04.840 回答