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 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 create a pluggable ASP.NET MVC framework. I have extensively used
I am trying to create divs dynamically in a view page of an asp.net
I am trying to merge my vb.net Web application project with my c# mvc
am getting this error on this code (this is an MVC project into which
In our ASP.NET MVC project, we have an HtmlHelper extension method to generate a
I'm trying to build custom AuthorizeAttribute, so in my Core project (a class library)
I am taking over quite a big ASP.NET MVC project, and I am just
I'm building a dynamic query in my ASP.NET MVC project by the following: Dim
I'm trying to use WCF Data Service with Subsonic, but ran into this error
How can I authenticate a user (with username and password) of an ASP.NET MVC

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.