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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:10:34+00:00 2026-06-09T12:10:34+00:00

I’ve made a CRUD MVC app which has something called Parts that are in

  • 0

I’ve made a CRUD MVC app which has something called Parts that are in certain relationships with each other.

PartMain      - o:m Section, o:m Report
PartSection   - m:o Main, o:m Property
PartProperty  - m:o Section, Contains MainID for sorting purposes, SortByMainID
PartReport    - m:o Main

All models are working and everything is ok on that part. Now I wish to generate a View that will show all data related to lets say selected PartMain. Like so:

PartMain: Name, Desc, etc... rest of data
    PartSection1: data...
        PartProperty1: data.. (all properties in relationship with that section)
    PartSection2: data... (all sections in relationship with selected PartMain)
        PartProperty1: data.. (all properties in relationship with that section)
    PartReport: data.... (all reports with selected PartMain)

I know I should do something like foreach loops in View but I’m having trouble grasping the logic, can anyone help?

Thanks.

PartMain contains Name and Desc properties, also is in o:m PartSection, and o:m PartReport. PartSection contains Name and Desc properties, also is in o:m PartProperty. PartProperty contains Name and Desc. PartReport contains Name and Version.

So what I want to do would be with pseudo code something like.
I tried this in controller, passed data with viewbag but nothing came back

pMainID = selectedMainID;
PartMain partMain = db.PartMain.Find(pMainID);
ViewBag.Name = partMain.Name
ViewBag.Desc = partMain.Desc

var partSections = db.PartSection.Where(s => s.pMainID = pMainID);

foreach (var partSec in partSections)
{
    ViewBag.PartSecName = partSec.Name
    ViewBag.PartSecDesc = partSec.Desc

    var partProperties = db.PartProperties.Where(p => p.pSecID = partSec.ID);
    foreach(var partProp in partProperties)
    {
        ViewBag.PartPropName = partProp.Name
        ViewBag.PartPropDesc = partProp.Desc
    }
}

Now that should output something like I mentioned above. Of course this code won’t work but that should be the general idea. That’s why I ask for help. Thank you.

  • 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-09T12:10:35+00:00Added an answer on June 9, 2026 at 12:10 pm

    Controller:

    var pMainID = selectedMainID;
    PartMain partMain = db.PartMain.Find(pMainID);
    
    ViewBag.Part = partMain;
    
    ViewBag.Sections = db.PartSection
        .Where(s => s.pMainID = pMainID)
        .Select(s => new
        {
            Section = s,
            Proeprties = db.PartProperties.Where(p => p.pSecID = partSec.ID)
        });
    

    View:

    <h1>@ViewBag.Part.Name</h1>
    <p>@ViewBag.Part.Desc</p>
    
    @foreach(var section in ViewBag.Sections)
    {
        <h2>@section.Section.Name</h2>
        <p>@section.Section.Desc</p>
    
        <dl>
        @foreach(var property in section.Properties)
        {
            <dt>@property.Name</dt>
            <dd>@property.Desc</dd>
        }
        </dl>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.