Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:22:34+00:00 2026-06-04T21:22:34+00:00

Aright so I have a database with a collection of Posts with a column/property

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:22:36+00:00Added an answer on June 4, 2026 at 9:22 pm

    OK. here is a suggestion; In this case it would be better if you could use a ViewModel

    public class PostsViewModel
    {
        public int Year;
        public List<MonthPosts> Posts;
    
        public class MonthPosts
        {
            public string Month { get; set; }   // or may be enum with Months
            public List<Post> MPosts{ get; set;}   // your collection of Posts if they carry many other column values that are needed at the view. If it is just to render the description, instead of list of posts you can pass the list of description of the Posts.
        }
    }
    

    In your controller From your Collection of Posts you should be able to fill in the PostsViewModel and return it to the view

    in your view

    @model IEnumerable<PostsViewModel>
    

    Now you should be able to iterate this in the view and render it according to your needs (archive format)

    pseudo syntax in view

    foreach(PostViewModel pvm in Model)
    {
        render pvm.Year
        foreach(PostViewModel.MonthPosts mp in pvm.Posts)
        {
             render mp.Month;
             foreach(Post p in mp.MPosts)
             {
                  render p.Description   //according to your needs
             }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a standalone application that needs to connect to a Sybase database via
I have an application built upon ASP.NET 3.5 and PostgreSQL 8.3. My database has
I have a file with database settings in my project which I have set
I have a Data Flow Task and am connecting to a database via an
I have an architect question: I want to use Tree View to display some
Alright, here's an odd one from an MS Access database I'm running. I have
Alright, so let's say I have a database with a table named COMPANY_PARAMETERS that
Alright, database stuff is turning out to be my rails weakpoint. I have 3
We have an application written in C language which interacts with Oracle database. This
I have some tables in a MySQL database to represent records from a sensor.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.