【问题标题】:MvcContrib Pager StylingMvcContrib 寻呼机样式
【发布时间】:2010-08-24 13:47:17
【问题描述】:

是否可以将 MvcContrib Grid 分页器设置为只显示“1 2 3 4 ...”进行分页?

【问题讨论】:

  • 或者是否可以删除寻呼机的“显示”部分?

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


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    有我对这个功能的实现:

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

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

    【讨论】:

    • 这是一个剃刀版本,但如果它更适合您的需要,您可以得到想法并将其转换为 aspx。
    猜你喜欢
    • 2011-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-28
    • 2011-03-31
    相关资源
    最近更新 更多