MVC contrib pager

2019-05-18 19:40发布

问题:

I am using it like this:

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

Is there are simple way to change the rendered url. I had a look for more documentation but couldn't find much.

回答1:

What exactly do you want to change?

This is how I change the URL:

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

You could also create a helper something like this:

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
    }


回答2:

It really depends on what do you want to change.

In the following sample I am changing the pagination links to use 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);
        }
    });
});


回答3:

You can pass in anything that is castable to IPagination. For example, see this SO question/answer: MvcContrib.UI.Grid pagination problem

You can also modify the pager after generation time using jQuery. See this post for an example: http://thekindofme.wordpress.com/2009/01/12/ajax-enabling-mvccontrib-grid-pagination-with-jquery/