ASP.NET MVC PaginatoredList 分页器 - 明智地说“...”在某一点之后

发布于 2024-12-04 11:22:07 字数 3917 浏览 0 评论 0原文

我已经为我的 ASP.NET MVC 项目创建了一个分页列表和分页器。效果很好,事情就是这样。

我无法弄清楚的一件事是如何在某个点之后放置 ... 。例如,假设我的寻呼机如下所示:

1 2 3 4 5 <代码>6 <代码>7 <代码>8 <代码>9 <代码>10 <代码>11 12 13 14 下一步>>

我需要的是如下内容:

1 2 3 4 5 6 7 8 9 10< /code> ... 下一步>>>

这里的 ... 是针对 11 的。当我们转到页面 11 时,寻呼机应如下所示:

... 11 12 13 14 Next >>>

这个实现是我不知道如何做到这一点的实现。

这是我当前的寻呼机代码的样子:

<div id="pager">

    @if (Model.PrimaryModel.HasPreviousPage) {
        @:@Html.ActionLink(
            "<<< Previous", 
            Model.Property["action"], 
            new { 
                controller = Model.Property["controller"], 
                Area = Model.Property["area"], 
                page = (Model.PrimaryModel.PageIndex - 1) 
            }, 
            new { 
                data_jquery_ajax_url = Url.Action(
                    string.Format("pagerAjaxCall_{0}", Model.Property["action"]), 
                    new { 
                        controller = Model.Property["controller"], 
                        Area = Model.Property["area"], 
                        page = (Model.PrimaryModel.PageIndex - 1) 
                    }
                ) 
            }
        )
    }

    @if (Model.PrimaryModel.TotalPages >= 2) {

        int totalPageNumber = 0;

        for (int i = 0; i < Model.PrimaryModel.TotalPages; i++) {

            int value = i + 1;

            if (Model.PrimaryModel.PageIndex == i) {
                @:@Html.ActionLink(value.ToString(), Model.Property["action"], new { controller = Model.Property["controller"], Area = Model.Property["area"], page = (i) }, new { @class = "active-page", data_jquery_ajax_url = Url.Action(string.Format("pagerAjaxCall_{0}", Model.Property["action"]), new { controller = Model.Property["controller"], Area = Model.Property["area"], page = (i) }) })
            } else { 
                @:@Html.ActionLink(value.ToString(), Model.Property["action"], new { controller = Model.Property["controller"], Area = Model.Property["area"], page = (i) }, new { data_jquery_ajax_url = Url.Action(string.Format("pagerAjaxCall_{0}", Model.Property["action"]), new { controller = Model.Property["controller"], Area = Model.Property["area"], page = (i) }) })
            }

            totalPageNumber++;
        }

        @*@:current : @(Model.PrimaryModel.PageIndex+1), totalPage @totalPageNumber.ToString(), right side @((totalPageNumber - Model.PrimaryModel.PageIndex)-1), left side @(totalPageNumber - (totalPageNumber - Model.PrimaryModel.PageIndex))*@
    }

    @if (Model.PrimaryModel.HasNextPage) {
        @:@Html.ActionLink(
            "Next >>>", 
            Model.Property["action"], 
            new { 
                controller = Model.Property["controller"], 
                Area = Model.Property["area"], 
                page = (Model.PrimaryModel.PageIndex + 1) 
            }, 
            new { 
                data_jquery_ajax_url = Url.Action(
                    string.Format("pagerAjaxCall_{0}", Model.Property["action"]), 
                    new { 
                        controller = Model.Property["controller"], 
                        Area = Model.Property["area"], 
                        page = (Model.PrimaryModel.PageIndex + 1) 
                    }
                ) 
            }
        )
    }

</div>

有什么想法吗?

I have created a paginatedList and pager for that for my ASP.NET MVC project. It works great, well thing so.

One thing that I cannot figure it out is to how to put ... after certain point. For example, lets say my pager looks like as follows :

1 2 3 4 5 6 7 8 9 10 11 12 13 14 Next >>>

What I need is some thing as follows :

1 2 3 4 5 6 7 8 9 10 ... Next >>>

the ... is for 11 here. When we go to page 11, the pager should be as follows :

... 11 12 13 14 Next >>>

This implementation is the one which I cannot figure it out how to do this.

And here is how my current pager code looks like :

<div id="pager">

    @if (Model.PrimaryModel.HasPreviousPage) {
        @:@Html.ActionLink(
            "<<< Previous", 
            Model.Property["action"], 
            new { 
                controller = Model.Property["controller"], 
                Area = Model.Property["area"], 
                page = (Model.PrimaryModel.PageIndex - 1) 
            }, 
            new { 
                data_jquery_ajax_url = Url.Action(
                    string.Format("pagerAjaxCall_{0}", Model.Property["action"]), 
                    new { 
                        controller = Model.Property["controller"], 
                        Area = Model.Property["area"], 
                        page = (Model.PrimaryModel.PageIndex - 1) 
                    }
                ) 
            }
        )
    }

    @if (Model.PrimaryModel.TotalPages >= 2) {

        int totalPageNumber = 0;

        for (int i = 0; i < Model.PrimaryModel.TotalPages; i++) {

            int value = i + 1;

            if (Model.PrimaryModel.PageIndex == i) {
                @:@Html.ActionLink(value.ToString(), Model.Property["action"], new { controller = Model.Property["controller"], Area = Model.Property["area"], page = (i) }, new { @class = "active-page", data_jquery_ajax_url = Url.Action(string.Format("pagerAjaxCall_{0}", Model.Property["action"]), new { controller = Model.Property["controller"], Area = Model.Property["area"], page = (i) }) })
            } else { 
                @:@Html.ActionLink(value.ToString(), Model.Property["action"], new { controller = Model.Property["controller"], Area = Model.Property["area"], page = (i) }, new { data_jquery_ajax_url = Url.Action(string.Format("pagerAjaxCall_{0}", Model.Property["action"]), new { controller = Model.Property["controller"], Area = Model.Property["area"], page = (i) }) })
            }

            totalPageNumber++;
        }

        @*@:current : @(Model.PrimaryModel.PageIndex+1), totalPage @totalPageNumber.ToString(), right side @((totalPageNumber - Model.PrimaryModel.PageIndex)-1), left side @(totalPageNumber - (totalPageNumber - Model.PrimaryModel.PageIndex))*@
    }

    @if (Model.PrimaryModel.HasNextPage) {
        @:@Html.ActionLink(
            "Next >>>", 
            Model.Property["action"], 
            new { 
                controller = Model.Property["controller"], 
                Area = Model.Property["area"], 
                page = (Model.PrimaryModel.PageIndex + 1) 
            }, 
            new { 
                data_jquery_ajax_url = Url.Action(
                    string.Format("pagerAjaxCall_{0}", Model.Property["action"]), 
                    new { 
                        controller = Model.Property["controller"], 
                        Area = Model.Property["area"], 
                        page = (Model.PrimaryModel.PageIndex + 1) 
                    }
                ) 
            }
        )
    }

</div>

Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残龙傲雪 2024-12-11 11:22:07

只是应该让您了解如何修复它

var start = Model.PrimaryModel.PageIndex > 10 ? Model.PrimaryModel.PageIndex : 0;

if (start > 0) { //create "..." }
for (int i = start; i <= Model.PrimaryModel.TotalPages && i < start + 10; i++) 
{ 
    //generate pages
}
if (start + 10 < 0 Model.PrimaryModel.TotalPages) { //create "..." }

Just should give you a general idea of how to fix it

var start = Model.PrimaryModel.PageIndex > 10 ? Model.PrimaryModel.PageIndex : 0;

if (start > 0) { //create "..." }
for (int i = start; i <= Model.PrimaryModel.TotalPages && i < start + 10; i++) 
{ 
    //generate pages
}
if (start + 10 < 0 Model.PrimaryModel.TotalPages) { //create "..." }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文