------Class
public class User
{}
----Controller
public class HomeController : Controller
{
private User user = new User();
public ActionResult Index(int? page,int? pageIndex)
{
int currentInt = page.HasValue ? page.Value - 1 : 0;
int currentIndex = pageIndex.HasValue ? pageIndex.Value - 1 : 0;
List<User> List = user.TableOneUser();
var viewModel = new CustomUser();
var one = List.Where(m => m.Id < 9).ToList();
var two = List.Where(m => m.Id > 9).ToList();
viewModel.One = one.ToPagedList(currentInt, 2, one.Count);
viewModel.Two = two.ToPagedList(currentIndex, 2, two.Count);
return View(viewModel);
}
public PartialViewResult TableOne(IPagedList<User> user)
{
return PartialView("TableOne",user);
}
public PartialViewResult TableTwo(IPagedList<User> user)
{
return PartialView("TableTwo",user);
}
}
------View
@model WebApplication8.Controllers.CustomUser
@{
ViewBag.Title = "About";
}
<H1>Table One</H1>
@Html.Partial("TableOne", @Model.One)
@Html.Pager(Model.One.PageSize, Model.One.PageNumber, Model.One.TotalItemCount).Options(o => o.PageRouteValueKey("page").AddRouteValue("pageIndex", Model.Two.PageNumber))
<H1>Table Two</H1>
@Html.Partial("TableTwo", @Model.Two)
@Html.Pager(Model.Two.PageSize, Model.Two.PageNumber, Model.Two.TotalItemCount).Options(o => o.PageRouteValueKey("pageIndex").AddRouteValue("page", Model.One.PageNumber))