4

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??

Community
  • 1
  • 1
Crime Master Gogo
  • 2,540
  • 10
  • 44
  • 75
  • possible duplicate of [Using paging in partial view, asp.net mvc](http://stackoverflow.com/questions/18822352/using-paging-in-partial-view-asp-net-mvc) – Guanxi Feb 11 '14 at 18:46

2 Answers2

5

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..

Community
  • 1
  • 1
Crime Master Gogo
  • 2,540
  • 10
  • 44
  • 75
1

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"}) )
Yogendra Paudyal
  • 1,297
  • 1
  • 12
  • 17