Using @Html.DisplayNameFor() with PagedList

后端 未结 5 667
囚心锁ツ
囚心锁ツ 2020-12-23 13:37

I\'ve been trying out the PagedList package to get paging for my index views. Everything was going well, and at the controller level everything is working fine, it only disp

5条回答
  •  抹茶落季
    2020-12-23 14:08

    You do not need to change @Html.DisplayNameFor. Declare model in the view as:

    @model IEnumerable
    

    Just move your pager to partial view (lets name it "_Pager"):

    @model IPagedList
    
    ...
    
    @Html.PagedListPager(Model, 
       page => Url.Action("Index", new { page, pageSize = Model.PageSize }))
    
    ...
    

    Render the pager in your view:

    @Html.Partial("_Pager", Model)
    

    Thats it.

    P.S. You can create Html helper instead of partial view...

提交回复
热议问题