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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:29:03+00:00 2026-05-13T08:29:03+00:00

In a MVC project am trying to create a view which has the Title

  • 0

In a MVC project am trying to create a view which has the Title from a parent table and the subsequent list below it from its related Child table.

I pulled the tables into the project using Entity Framework and in the controllers namespace created the follwing Viewmodel:

public class ServicesViewModel
{
    public ServicesViewModel(List<ServiceGroup> servicegroups, List<Service> services)
    {
        this.ServiceGroups = servicegroups;
        this.Service = services;
    }

    public List<ServiceGroup> ServiceGroups { get; set; }
    public List<Service> Service { get; set; }

}

Then in the controller Actionresult I did this:

    public ActionResult Index()
    {

        var servicegroups = _db.ServiceGroupSet.ToList();
        var services = _db.ServiceSet.ToList();

        return View(new ServicesViewModel(servicegroups,services));
    }

..And in the View did this:

” %>

Other html code etc..

<% foreach (var m in Model.ServiceGroups) { %>

    <strong><ul> <%= m.ServiceGroupName %></ul></strong>

<% foreach (var item in Model.Service) { %>

    <li> <%= item.ServiceDescription %></li>

<% } %>


<% } %>

It all wires up ok but runs ALL child records for each parent record. I have not figured how to put that parameter which filters into the view.

I tried a linq query in the controller but can’t seem to find the foreign key field in the intellisense.

  • 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-05-13T08:29:03+00:00Added an answer on May 13, 2026 at 8:29 am

    Hmmm.. if it is a Master-Detail 2 tables and you want to have a separate view model, I’d recomend that you define you as ServiceGroup + List and then pass list of this to view.

    But if Your Service and ServiceGroup do have their own navigation properties (EF or LINQ2SQL).
    You can just pass ServiceGroups to view and there use Navigation Property ServiceGroup.Services to enumerate details.

    <% foreach (var m in Model.ServiceGroups) { %>
    
        <strong><ul> <%= m.ServiceGroupName %></ul></strong>
    
    **<% foreach (var item in m.Services) { %>**
    
        <li> <%= item.ServiceDescription %></li>
    
    <% } %>
    
    
    <% } %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to start a new MVC project with tests and I thought
I've just create a new MVC project, and have made no changes at all,
So I'm embarking on an ASP.NET MVC project and while the experience has been
I'm trying to create an iphone app which grabs a JSON string, parses it
I'm trying to add a navigational menu for my project which uses the ASP.NET
I am using an ASP.NET MVC project and everytime I add a class to
I'm working on a Spring MVC project, and I have unit tests for all
I have an ASP.NET MVC project with a form. In the Action method that
I have an ASP.NET MVC project and I have a single action that accepts
I have a new ASP.NET MVC project (my first), and I had been running

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.