Is there a paging solution for ASP.NET MVC that does paging in the database?

前端 未结 4 1708
小蘑菇
小蘑菇 2021-02-02 17:35

Most of the ASP.NET MVC paging solutions I have found by googling look like they get all rows from a database table in the form of a IEnumerable collection, perform some paging

相关标签:
4条回答
  • 2021-02-02 17:50

    wouldn't it be more efficient to implement a stored procedure that takes @StartPage and @PageSize parameters?

    this way you are only retrieving the subset of data that is actually being used

    just have an out parameter called totalCount or something similar so that you know how many page links to create and each link onclick event will pass the page number to a javascript function that will asynchronously load the div or other HTML element with more data

    easy

    0 讨论(0)
  • 2021-02-02 17:51

    ScottGu has a very nice multi-part blog series on using LINQ in Asp.Net (including MVC). I recommend reading the entire series starting at Part 1, but Part 3 covers exectly what you're looking for -- the section titled "Paging our Query Results" specifically deals with paging in the database.

    0 讨论(0)
  • 2021-02-02 17:57

    You're wrong. PagedList will do it on the DB server, as it has IQueryable extensions.

    0 讨论(0)
  • 2021-02-02 18:09

    Look at the Gu's Nerdinner sample.

    var upcomingDinners = dinnerRepository.FindUpcomingDinners();  
    var paginatedDinners = upcomingDinners.Skip(10).Take(20).ToList(); 
    

    Even though FindUpcomingDinners() gets all the upcoming dinners, the query isn't executed at the database until you call ToList() in the next line. And that is after you Skip 10 rows and only get
    the next 20.

    0 讨论(0)
提交回复
热议问题