MVC 自动分页控件

http://blogs.taiga.nl/martijn/ 

在html页

@modelIPagedList<SchoolProgress.Web.Models.StudentModel>

 

@Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount).Options(o => o

      .DisplayTemplate("BootstrapPagination")

              .MaxNrOfPages(30)

            .AlwaysAddFirstPageNumber()

     .AddRouteValue("SchoolPaging", Request.QueryString["SchoolId"]))

在controller里

privateint _pageSize = Convert.ToInt32(ConfigurationManager.AppSettings["TablePageSize"]);

publicActionResult Index(int schoolId, int? page)

 

        {

           int currentPageIndex = page.HasValue ? page.Value - 1 : 0;

           var studentDomain = _unityOfWork.StudentRepository.GetBySchoolId(schoolId);

           var students = studentDomain.Select(m => m.ToModel());

           return View(students.ToPagedList(currentPageIndex, _pageSize));

 

        }

webConfig中

<addkey="TablePageSize"value="5"/>

 

如果controller中没有其他参数publicActionResult Index(int? page)

@Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount).Options(o => o

      .DisplayTemplate("BootstrapPagination")

 

              .MaxNrOfPages(30)

            .AlwaysAddFirstPageNumber()

     //.AddRouteValue("SchoolPaging", Request.QueryString["SchoolId"]))  取消这行

 

你可能感兴趣的:(MVC 自动分页控件)