Paging in asp.net mvc like blogger

665 views Asked by At

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 should contain the number of items configurable.

Any ideas on this?

2

There are 2 answers

0
m3kh On

It's not exactly what you want, but you can figure it out.

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

0
Andy Long On

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.