简体   繁体   English

在ASP.NET MVC中分页,例如Blogger

[英]Paging in asp.net mvc like blogger

I like to implement a paging in my asp.net mvc(C#) application like the one in blogger(blogspot.com). 我喜欢在asp.net mvc(C#)应用程序中实现分页,就像在blogger(blogspot.com)中那样。

The Paging should look like: 分页应如下所示:

   `New Posts                      Home                    Older Posts`

The Page should contain the number of items configurable. 页面应包含可配置的项目数。

Any ideas on this? 有什么想法吗?

It's not exactly what you want, but you can figure it out. 这不是您想要的,但是您可以弄清楚。

http://mgolchin.blogspot.com/2009/06/mvc-datapager.html http://mgolchin.blogspot.com/2009/06/mvc-datapager.html

The easiest way to do this would be to find the next and previous articles/blogs in your controller and then pass these into the view using ViewData, ie 最简单的方法是在控制器中查找下一个和上一个文章/博客,然后使用ViewData将它们传递到视图中,即

ViewData["NextPost"] = Model.GetNextPost();
ViewData["PrevPost"] = Model.GetPrevPost();

Then simply display these in your view: 然后只需在您的视图中显示它们即可:

<ul>
    <li><%= Html.Action("New posts", new { Action = "View", Id = (Post)ViewData["NextPost"].Id }) %></li>
    <li><%= Html.Action("Home", new { Action = "Home" }) %></li>
    <li><%= Html.Action("Old posts", new { Action = "View", Id = (Post)ViewData["PrevPost"].Id }) %></li>
</ul>

You will need to style the ul to make it look nice. 您将需要设置ul的样式以使其看起来不错。 If you then want to make this piece of code reusable, you could put the display code in a partial view. 如果然后要使这段代码可重用,则可以将显示代码放在部分视图中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM