2010-12-15 158 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); 
     } 
    }); 
});