如何在asp.net mvc3中进行分页?
我正在开发 asp.net mvc3 应用程序,并且有许多来自数据库的记录。我想先只显示 10 条记录,然后用户可以单击按钮查看接下来的 10 条记录,依此类推...就像 Facebook 墙上发布更多记录一样。
我如何使用 jQuery 和 ajax 在我的应用程序中实现这个东西?
如何使用分页控制视图中的数据显示?
我使用它来获取 10 条记录,但我想使用更多记录按钮显示所有记录
var Entity = (from a
in context.Data
where <Condition>
select a).Take(10);
I am working on asp.net mvc3 application and have many records coming from database. I want to display only 10 records first then user can click on button to see next 10 records and so on... Like facebook wall posting more records.
How can I implement this thing in my application using jQuery and ajax?
How can I control display data in view using paging?
I am using this to get 10 records but I want to display all records using more record button
var Entity = (from a
in context.Data
where <Condition>
select a).Take(10);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下文章应该会给您一个想法:
http://weblogs.asp.net/andrewrea/archive/2008/07/01/asp-net-mvc-quot-pager-quot-html-helper.aspx
http://weblogs.asp.net/gunnarpeipman/archive/2010/02/21/simple-pager-for-asp-net-mvc.aspx
另一方面,您可以像这样实现它this :
获取名为 TugberkUg.MVC 的 nuget 包
然后,您的控制器应如下所示:
并且,您的控制器应如下所示:
您还需要处理寻呼机,这里是一个示例适合您:
ASP.NET MVC PagulatedList Pager - Putwise在某个点之后的“...”
这个
TugberkUg.MVC.Helpers.PaginatedList
类将为寻呼机提供所有必需的字段。The following articles should give you an idea :
http://weblogs.asp.net/andrewrea/archive/2008/07/01/asp-net-mvc-quot-pager-quot-html-helper.aspx
http://weblogs.asp.net/gunnarpeipman/archive/2010/02/21/simple-pager-for-asp-net-mvc.aspx
On the other hand, you can implement it like this :
Get the nuget package called TugberkUg.MVC
Then, your controller should look like below :
And, here how your controller should look like :
You need to handle the pager as well and here is a sample for you :
ASP.NET MVC PaginatedList Pager - Put wise "..." after certain point
This
TugberkUg.MVC.Helpers.PaginatedList
class will provide all the necessary fields for pager.我不知道有任何 .net 库可以为您提供开箱即用的分页功能,因此我将推出一个 DIY 解决方案供您考虑。
对于 ajax 请求有一个特定的控制器可能是明智的。只需有一个单独的区域(Ajax),并将您的 ajax 请求发送到您设置的 URL 即可。
设置一个接受“页面”参数的控制器。
公共 ActionResult GetData(int? page){
// page 可以为 null 以允许默认页面
}
我不确定您是否需要除此之外的更多信息。如果我想做你正在做的事情,这就是我会做的。希望有帮助。
I'm not aware of any .net library that will do pagination for you out of the box, so I will roll out a DIY solution for you to think about.
It is probably wise to have a specific Controller for ajax requests. Just have a separate Area (Ajax), and send your ajax requests to that url you set up.
Set up a controller that takes in a "page" parameter.
public ActionResult GetData(int? page){
// page is nullable to allow for default page
}
I'm not sure if you require more information other than this. If I were trying to do what you were doing, this is what I would do. Hope that helps.
如果您使用 Webgrid 来显示数据,那么 rowsperpage 就可以了。
If your are using Webgrid to display data then rowsperpage will do.