2010-08-31 100 views
0

你好我的代碼,我給拿出來看分頁:尋呼與asp.net的MVC C#

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

我想說明永遠只是一個兩頁在選定頁面之前和之後。 如果Iam在第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)); 

回答

1

那麼首先,你的視圖是相當複雜的。

爲什麼不使用HTML擴展方法來簡化UI和分頁?

有很多例子,我個人喜歡this之一。