Ok so I had the basics of an ASP.NET MVC blog site up and running. I had my data layer written using LINQ, I had my business layer defined with Services and Entities, and I was starting to build my MVC code on top of those.
But now I was finding that I needed to page a number of things such as
- User lists when administering site
- Blog lists when administering site
- Blog entries
- Tag management
And I'm sure there are a few other things that I'm forgetting about right now, but those are the bigs ones I recall.
So how did I do it? Well at first I was thinking about writing my own control, but then I decided I'd do a little research first and see what other people were doing. It was definitely possible that something already existed in the MVC framework that I didn't know about.
Well after searching for a while I came to the conclusion that there wasn't anything in MVC yet, but there were some alternatives. In particular I found this and this. I ended up going with the first one that I found on Rob Conery's blog. Overall it worked perfectly.
I only made a couple of minor tweaks related to constructors. There were a couple of situations where I wanted to create a new Pager class instance without any params. Essentially an empty paged list element. Other than that, everything worked as advertised.
That's it, it worked well. You can see the results when you view a blog that has more than 10 posts now.
*Quick note. Its actually kind of funny. I was going to post this entry and I was going to have more than 10 posts in my software blog. Cool I thought. I'll actually use the paging now. Well the paging didn't work! I only got an option for a single page in my page index control, and I couldn't see this newly entered post!
Its never easy is it...
At first I thought there was a problem with the Paging code. Nope, that worked like a champ. Then I thought, maybe its my rendering code. Nope that was fine as well. Turns out I had somehow created a Paged Lists with my Query results, then made a Paged List out of THAT. The second paged list only saw the items on a single page instead of the total number of items. So my code never thought it had a total item count greater than a page. I fixed that problem in how I was using the Paged List classes and it all worked fine.