Aright so I have a database with a collection of Posts with a column/property called CreationDate. I was wondering how my ViewModel would look to display an Archive like so:
..............
. 2012 .
. Feb .
. PostA .
. PostB .
. PostC .
. Mar .
. PostD .
. May .
. PostE .
..............
At first I though why don’t I sort through the dates in the Controller but it ended up being a bunch of foreach loops that would loop through each post and see if the Controller had already made a container for each year|month.
Another thought I had was to add more columns to my database called year and month. That way I could get all the different Years and their corresponding months but I’m not exactly sure how that would look though nor if I want those columns in my database/ on my entity…
Any suggestions?
OK. here is a suggestion; In this case it would be better if you could use a
ViewModelIn your controller From your Collection of Posts you should be able to fill in the
PostsViewModeland return it to the viewin your view
Now you should be able to iterate this in the view and render it according to your needs (archive format)
pseudo syntax in view