Paging partialview with PagedList

10,252

Solution 1

well, I found the answer. Someone else had the similar question that I just found out...

here is it: Using paging in partial view, asp.net mvc

and it works just fine..

Solution 2

You can use PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing for ajaxifying the page no link, which returns the partial view.

In Controller:

 if (Request.IsAjaxRequest())
 {
    //viewModel=your viewModel
    return PartialView("viewModel");
  }

In View:

@Html.PagedListPager( Model, page => Url.Action("StudentList", new { page, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter }),PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing( new AjaxOptions(){  HttpMethod = "GET", UpdateTargetId = "student_table"}) )
Share:
10,252
Crime Master Gogo
Author by

Crime Master Gogo

Updated on August 21, 2022

Comments

  • Crime Master Gogo
    Crime Master Gogo over 1 year

    i have a partialview that has tabular data.. i am using PagedList for paging.

    it works good with a normal view, but when I tried to put it on a partial view, when I click next or any other pages, it just refreshes the whole page and my view breaks :(

    I want to refresh the partialview only meaning when I perform pagination, i just want to change the partialview not the whole view.

    this is the code for pagination i my partialview...

    Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
    @Html.PagedListPager( Model, page => Url.Action("StudentList", new { page, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter }) )
    

    i tried to put Ajax.ActionLink instead of Url.Action with no success... any help??