2010-12-15 138 views
2

我使用它是這樣的:MVC的contrib尋呼機

<%= Html.Pager((IPagination)Model) %> 

是否有簡單的方法來改變呈現的網址。我查看了更多文檔,但找不到太多內容。

+0

那你想幹什麼? – Lorenzo 2010-12-15 16:26:14

+0

我的問題是,我在控制器的索引視圖中有一個網格,並且該操作位被吞下。它適用於其他視圖,但不適用於索引視圖。所以我認爲我可以強制創建動作位以生成正確的URL。 – cs0815 2010-12-16 10:54:46

+0

我嘗試了<%= Html.Pager((IPagination)Model) .Link(currentPage => Url.Action(「Index」,new {​​page = currentPage })) %但是索引位是swalloed。如果我使用「Bla」而不是「Index」,則會生成URL。爲什麼是這樣?謝謝。 – cs0815 2010-12-16 11:01:00

回答

9

你到底想要改變什麼?

我這是怎麼改變的網址:

Html.Pager(Model.AssetsPagedList) 
     .First("First") 
     .Last("Last") 
     .Next("Next") 
     .Previous("Previous") 
      .Link(currentPage => Url.Action("Browse", new { 
      page = currentPage, 
      searchTerm = Model.SearchModel.SearchTerm, 
      excludedWords = Model.SearchModel.ExcludedWords, 
      minPrice = Model.SearchModel.MinPrice, 
      maxPrice = Model.SearchModel.MaxPrice, 
      locationId = Model.SearchModel.LocationId, 
      catalogId = Model.SearchModel.CatalogId 
     })) 

你也可以創建一個幫助是這樣的:

public static Pager Pager(this HtmlHelper helper, IPagination model, FormCollection formCollection) 
    { 
     // here you can use MvcContrib.UI.Pager.PaginationExtensions.Pager static methods 
     // or create MvcContrib.Pagination.Pager class directly 
    } 
+0

我試過<%= Html.Pager((IPagination)Model).Link(currentPage => Url.Action(「Index」,new {page = currentPage}))%>,但索引位是swalloed。如果我使用「Bla」而不是「Index」,則會生成URL。爲什麼是這樣?謝謝。 – cs0815 2010-12-16 11:01:20

+0

不知道。如果你想弄明白,你可以下載源代碼,編譯它並使用調試器。代碼並不複雜。 – rboarman 2010-12-16 16:55:30

+0

對我來說這不起作用,因爲現在頁面對於下一頁(頁面= 1)和上一頁(頁面= 1)是相同的。你需要在鏈接代表中區分它們,但你不能。我錯過了什麼? – Rookian 2012-09-23 10:32:36

1

這真的取決於你想改變什麼事情。

在下面的示例,我改變了分頁鏈接使用AJAX

$("#addressListPlaceholder .paginationRight a").click(function (event) { 
    event.preventDefault(); 
    $.ajax({ 
     type: "get", 
     dataType: "html", 
     url: this.href, 
     data: {}, 
     success: function (response) { 
      $("#addressListPlaceholder").html('').html(response); 
     } 
    }); 
});