ASP.NET MVC 中的分页
我有一个 asp.net 网站,我在其中使用以下代码对后面的代码进行分页:
PagedDataSource objPds = new PagedDataSource
{
DataSource = ds.Tables[0].DefaultView,
AllowPaging = true,
PageSize = 12
};
为 asp.net-mvc 进行分页的等效最佳方法是什么。我认为这实际上属于视图代码。
i have an asp.net website where i do paging through on the code behind using:
PagedDataSource objPds = new PagedDataSource
{
DataSource = ds.Tables[0].DefaultView,
AllowPaging = true,
PageSize = 12
};
what is the equivalent best way of doing paging for asp.net-mvc. I would think this would actually belong in the view code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我只会定义一个带有页码的自定义路由:
会给你这种类型的Url:
然后在你的控制器操作中你会得到这个页码:
所以你的视图实际上不会知道当前页面。它只会显示提供的记录列表。
您还需要直接在此视图中或在母版页中生成各个页面的链接。
I would just define a custom route with the page number in it:
Will give you this kind of Url:
Then in your controller action you get this page number:
So your view will not actually be aware of the current page. It will just display a list of supplied records.
You will also need to generate links to various pages either in this view directly or maybe in your master page.
Nerddinner 项目中有一个很好的分页类示例:
There is a good paging class example in the Nerd Dinner project:
如果您购买:
专业 ASP.NET MVC 1.0(Wrox 程序员到程序员)
其中关于 Ajax 和 JsonResult 的部分...非常好的演练如何设置 javascript 和非 javascript 解决方案。我还没有真正实现它,所以我不太记得它,我只记得当我读它时,我认为它非常适合我的新网站上的分页。
这里也有不错的教程:
http://www.asp.net/learn/mvc/tutorial- 32-cs.aspx
If you buy:
Professional ASP.NET MVC 1.0 (Wrox Programmer to Programmer)
The section in there about Ajax and JsonResult ... very good walkthrough of how to set up both an javascript and non-javascript solution. I haven't actually implemented it, so I don't remember too much about it, I just remember when I read it, I thought it would work perfectly for paging on my new site.
Decent tutorial here as well:
http://www.asp.net/learn/mvc/tutorial-32-cs.aspx
我将解释在asp.net mvc中实现分页的方法。
ProductController.cs
ProductModel.cs
Index.aspx
I will explain the way to implement pagination in asp.net mvc.
ProductController.cs
ProductModel.cs
Index.aspx