是否有一个分页解决方案为ASP.NET MVC在数据库中进行分页? [英] Is there a paging solution for ASP.NET MVC that does paging in the database?

查看:137
本文介绍了是否有一个分页解决方案为ASP.NET MVC在数据库中进行分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过googling发现的大多数ASP.NET MVC分页解决方案看起来像是从一个数据库表中以IEnumerable集合的形式获取所有行,对IEnumerable集合执行一些分页转换,然后将结果返回风景。我想能够在数据库端的页面,但仍然有一些分页类做页面计算和HTML生成。有没有解决方案,有这样做?或者是我一直在寻找这样做,但我没有看到它,因为我看他们错了?

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 conversion on the IEnumerable collection, and then return the results to the view. I want to be able to page on the DB side but still have some paging class to do the page number calculations and HTML generation. Is there a solution out there that does this? Or are the ones i've been looking at do this, but i'm not seeing it because i'm looking at them wrong?

这是我一直在查看:

  • http://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/
  • http://www.codeproject.com/KB/aspnet/pagination_class.aspx
  • http://www.squaredroot.com/2009/06/15/return-of-the-pagedlist/

推荐答案

查看顾氏的 Nerdinner 示例。

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

即使FindUpcomingDinners()获取所有即将到来的晚餐,查询才会在数据库中执行,直到你在下一行调用ToList()。这是你跳过10行后,只得到
下20个。

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.

这篇关于是否有一个分页解决方案为ASP.NET MVC在数据库中进行分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆