0

你好,它是我的代码,我在其中给出分页视图:

<div style="float: right;">
        <%= Html.RouteLink("<<", new { page = 1 }, new { title = "first page" })%>
        <% if (this.Model.HasPreviousPage)
           {%>

        <%= Html.RouteLink("<", new { page = (Model.PageIndex - 1) }, new { title = "previous page"})%>
        <%} %>

        <%  
            for (int i = 1; i <= this.Model.PageIndex + 2; i++)
            { if(i <= this.Model.TotalPages){
                 %>

        <%= Html.ActionLink(Convert.ToString(i), "Overview", new { page = i }, new { title = i + " page"})%>
        <% }}%>

        <% if (this.Model.HasNextPage)
           {%>

        <%= Html.RouteLink(">", new { page = (Model.PageIndex + 1) }, new { title = "next page"})%>
        <%} %>
        <%= Html.RouteLink(">>", new { page = Model.TotalPages }, new { title = "last page" })%>
    </div>

它看起来像这样:

<< 1 2 3 > >>

我想在所选页面之前和之后始终只显示两页。如果我在第 4 页,我会像这样看到之前的所有 3 页。

<< < 1 2 3 **4** > >>

我该怎么做,请帮帮我.. 目前我脑子里的库存很少,不知道如何操作。

我的模型有以下分页数据:

  /// <summary>
        /// Gets the boolean value of previous page
        /// </summary>
        public bool HasPreviousPage
        {
            get
            {
                return (PageIndex > 1);
            }
        }

        /// <summary>
        /// Gets the boolean value of next page
        /// </summary>
        public bool HasNextPage
        {
            get
            {
                return (PageIndex + 1 <= TotalPages);
            }
        }

        /// <summary>
        /// gets total pages of overview.aspx
        /// </summary>
        public int TotalPages
        {
            get
            {
                return _totalPages;
            }
            set
            {
                _totalPages = value;
            }
        }

        /// <summary>
        /// gets total count 
        /// </summary>
        public int TotalCount
        {
            get
            {
                return _totalCount;
            }
            set
            {
                _totalCount = value;
            }
        }

        /// <summary>
        /// gets actual page index
        /// </summary>
        public int PageIndex
        {
            get
            {
                return _pageIndex;
            }
            set
            {
                _pageIndex = value;
            }
        }

        /// <summary>
        /// gets page size
        /// </summary>
        public int PageSize
        {
            get
            {
                return _pageSize;
            }
            set
            {
                _pageSize = value;
            }
        }




 PageSize = 5;
                PageIndex = page;
                TotalCount = Threads.Count;
                TotalPages = TotalCount / PageSize;

                int pageResult = 0;
                for (int counter = 1; pageResult < this.TotalCount; counter++)
                {
                    pageResult = counter * this.PageSize;
                    TotalPages = counter;
                }

                FirstThreads = new List<Thread>();
                FirstThreads.AddRange(Threads.Skip<Thread>((PageIndex - 1) * PageSize).Take<Thread>(PageSize));
4

1 回答 1

1

首先,您的视图相当复杂。

为什么不使用 HTML 扩展方法来简化 UI 和分页?

周围有很多例子,我个人喜欢这个

于 2010-08-31T09:46:53.000 回答