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).
The Paging should look like:
`New Posts Home Older Posts`
The Page shou开发者_开发技巧ld 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
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, i.e.
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. If you then want to make this piece of code reusable, you could put the display code in a partial view.
精彩评论