使用PagedList的自定义分页asp.net

问题描述 投票:0回答:1

我本学期开始学习ASP.NET。我们得到了一个制作简单的3x2画廊的任务,并且还需要以指定的方式显示分页(对不起,我的英语)。

我们正在使用ASP.NET MVC 4,C#和分页应如下所示:

上一个1 2 3 4 5 ... 20下一个

使用页面列表,我能够显示此内容:

上一个1 2 3 4 5 ...下一个

我需要一些帮助来显示20。请帮我。

Index.cshtml

@Html.PagedListPager(Model, page => Url.Action("Index", new { page }), new PagedListRenderOptions {

        DisplayLinkToPreviousPage = PagedListDisplayMode.Always,
        DisplayLinkToLastPage = PagedListDisplayMode.Never,
        MaximumPageNumbersToDisplay = 5,
        LinkToNextPageFormat = "Next",
        LinkToPreviousPageFormat = "Prev"

})

控制器中的索引方法:

public ActionResult Index(int ? page)
    {
        return View(db.Galleries.ToList().ToPagedList(page ?? 1,6));
    }

请帮助我。谢谢。

c# asp.net asp.net-mvc-4 pagination pagedlist
1个回答
0
投票

我想您正在使用https://github.com/troygoode/PagedList中的PagedListPager?选项在源代码的PagedListRenderOptions.cs中进行了描述。

看来您应该说这样的话,以获得指向仅包含页码的最后一页的链接。

@Html.PagedListPager(Model, page => Url.Action("Index", new { page }), new PagedListRenderOptions {
    DisplayLinkToLastPage = PagedListDisplayMode.Always,
    LinkToLastPageFormat = "{0}"
})
© www.soinside.com 2019 - 2024. All rights reserved.