Using a PagedList with a ViewModel ASP.Net MVC

后端 未结 5 2009
暖寄归人
暖寄归人 2020-11-29 01:09

I\'m trying to using a PagedList in my ASP.Net application and I found this example on the Microsoft website http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-m

5条回答
  •  温柔的废话
    2020-11-29 01:55

    The fact that you're using a view model has no bearing. The standard way of using PagedList is to store "one page of items" as a ViewBag variable. All you have to determine is what collection constitutes what you'll be paging over. You can't logically page multiple collections at the same time, so assuming you chose Instructors:

    ViewBag.OnePageOfItems = myViewModelInstance.Instructors.ToPagedList(pageNumber, 10);
    

    Then, the rest of the standard code works as it always has.

提交回复
热议问题