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

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

问题描述

大多数我已经使用Google看起来像他们从一个IEnumerable集合形式的数据库表中的所有行中发现的ASP.NET MVC分页的解决方案,执行对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?

这就是我一直在寻找:

推荐答案

看顾的 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天全站免登陆