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

  • SEARCH
  • Home
  • 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 8988465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:00:57+00:00 2026-06-15T22:00:57+00:00

I have been studying EF and LINQ for quite a while now and I’m

  • 0

I have been studying EF and LINQ for quite a while now and I’m stumped on my inability to gather answer on the process that I’m trying to accomplish below:

In the index view, I would like to have a tabular list of all CD with their respective Contents. Please see below classes for more info:

 public class Cd
    {
        public int cdID { get; set; }
        public string cdName { get; set; }
        public string tag { get; set; }
        public Content Content { get; set; }
    }

    public class Content
    {

        public int contentID { get; set; }
        public string contentName { get; set; }
        public string category { get; set; }
    }

Given the classes, how can I achieve what I’m trying to do – display all CD contents under a CD using an cdID?

Update #1 – Final Answer ( thanks to DryadWoods)

public class Cd
{
    public int cdID { get; set; }
    public string cdName { get; set; }
    public string tag { get; set; }
    public IList<Content> Content { get; set; }  //Changes here! No changes in Content class
}

Final Version of the view:

@model IEnumerable<MediaManager.Models.Cd>

<table>
    <tr>
        <th>CD ID</th>
        <th>Content</th>
    </tr>

    @foreach (var cd in Model) //nested loop for displaying the cdID, then proceeds to loop on all contents under certain cdID
    {
        <tr>

            <td>
                @Html.DisplayFor(modelItem => cd.cdID)
            </td>
            <td>
            @foreach (var item in cd.Content)
            {
                <p>@item.contentName</p>
            }
            </td>
        </tr>
    }

</table>
  • 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-15T22:00:58+00:00Added an answer on June 15, 2026 at 10:00 pm

    Simple example to have one page where you display all CDs and each one’s content.

    Controller:

        public ViewResult Index(){
               return View(db.Cd.Include(x=>x.Content).ToList());
        }
    

    View:

        @model IEnumerable<YourNamespace.Cd>
    
        @foreach (var cd in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => user.UserName)
                       .... etc ...
            </td>    
            <td>
                @foreach (var c in cd.Content ) {
                  <div>
                       @c.contentName 
                       .... etc ...
                  </div>
                }
            </td>            
        </tr>
         }
    

    UPDATE #1

    change the class to:

     public class Cd
        {
            public int cdID { get; set; }
            public string cdName { get; set; }
            public string tag { get; set; }
            public IList<Content> Contents { get; set; }
        }
    

    Now you have a list of “contents” 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been studying Grails for quite a while now. And scanned a little
I have been studying python for quite sometime now and very recently I decided
I am trying to teach ASP.NET MVC to students (undergrads) that have been studying
I have been studying unicode and its Python implementation now for two days, and
Have been trying to encrypt an xml file to a string so that I
I have been studying the ECMAScript specification and have found that it is extremely
I'm new to Python. Have been studying it with courses on udacity and now
I have been studying the database structure for shopping carts and notice that when
I have been programming for a couple of years and am now studying computer-science
I've been studying and making little games for a while, and I have decided

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.