MVCPaging MultiTable 多个Table

------Class  

  public class User

    {
        public int Id { set; get; }
        public string Name { set; get; }

        public  List<User> TableOneUser()
        {
             var One = new List<User>();
             One.Add(new User(){Id=1,Name = "a"});
             One.Add(new User(){Id=11,Name = "aa"});
            return One;
        }
    }

    public class CustomUser
    {
        public IPagedList<User> One { set; get; }
        public IPagedList<User> Two { set; get; }
    }

}

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

你可能感兴趣的:(MVCPaging MultiTable 多个Table)