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 8037181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:51:03+00:00 2026-06-05T02:51:03+00:00

I’m trying to put together (what I thought was) a simple ASP.NET web application

  • 0

I’m trying to put together (what I thought was) a simple ASP.NET web application using MVCScaffolding and ASP.NET. There is a basic hieararchy of data tables in SQL: dbo.Albums, dbo.Tracks.

The model is easy. For albums:

public class Albums {
public int ID { get; set; }
public string Artist { get; set; }
    public string AlbumTitle { get; set; }
public string Notes { get; set; } 
}

public class Tracks {
public int ID { get; set; }
public int AlbumID { get; set; }
public string TrackTitle { get; set; }
public string Notes { get; set; }
}

The basic CRUD views are built and working fine. However, I’m trying to build a view that displays the Album model data followed by a table with one row for each track record for a given AlbumId. Essentially, this is the Details view followed by the Index view from the MVCScaffolding template, but it uses two Models and has one parameter (the ID from Albums table).

I tried to add the models together to access the data from there, but I can’t figure out how to iterate over a list (the index view uses @model IEnumerable<Music.Models.Tracks>). This is the combined model:

public class AlbumsExtended
{
    public Albums Albums { get; set; }
    public Tracks Tracks { get; set; }
}

And I am trying to access it in AlbumsExt.cshtml with @model Music.Models.AlbumsExtended. The controller looks like this:

public ViewResult AlbumExt(int id)
    {
        return View(tracksRepository.All.Where(tracks => tracks.AlbumId == id));
    }

But obviously that isn’t correct.

  • 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-05T02:51:05+00:00Added an answer on June 5, 2026 at 2:51 am

    Given your structure of Albums and Tracks, it would probably be preferable to have a direct 1 to many relationship between Albums and Tracks so that 1 album can have many tracks. Regardless of how many albums a track may appear on, your models could look like:

    public class Albums {
        public int ID { get; set; }
        public string Artist { get; set; }
        public string AlbumTitle { get; set; }
        public string Notes { get; set; } 
        public IQueryable<Track> Tracks { get; set; }
    }
    
    public class Track {
        public int ID { get; set; }
        public int AlbumID { get; set; }    // This may be unnecessary 
        public string TrackTitle { get; set; }
        public string Notes { get; set; }
    }
    

    This would allow your data layer to populate all of the tracks that belong to a specific Album, but if you don’t need to know the tracks it can just remain null. But your data layer just needs to fetch the album and then populate the Tracks property with an IQueryable object.

    public ViewResult AlbumExt(int id)
    {
        Album album = albumRepository.All.Where(a => a.ID == id);
        album.Tracks = tracksRepository.All.Where(t => t.AlbumId == id);
        return View(album);
    }
    

    This would give you a single model, but all of the related tracks would still be accessible through the Model.Tracks property in the view:

    @model MyNameSpace.Album
    
    @{
        foreach (var track in Model.Tracks)
        {
            <text>
                <h1>@track.TrackTitle</h1><br />
            </text>
        }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.