MvcContrib寻呼机造型

时间:2010-08-24 13:47:17

标签: asp.net asp.net-mvc-2 mvccontrib mvccontrib-grid

是否可以将MvcContrib网格寻呼机设置为只显示“1 2 3 4 ...”进行分页?

2 个答案:

答案 0 :(得分:0)

据我所知,该选项并不是开箱即用的。我在codeplex上问了同样的问题,但它似乎尚未准备就绪:

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

答案 1 :(得分: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>

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