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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:01:15+00:00 2026-05-13T16:01:15+00:00

I am new to web apps, MVC, and LinqToSql. I created an MVC web

  • 0

I am new to web apps, MVC, and LinqToSql. I created an MVC web app using the NerdDinner tutorial as a guide. I’m now adding many-to-many relationships to it. And am just running into walls at every step. I have a multiselect list in the Edit and Create views. For the Detail and List views I would like to list the selected values.

I have 3 tables: Company, Subcontract, and a link table CompanyToSubcontract. I have code which gets the guid of my selected companies from the CompanyToSubcontract table which is used elsewhere in my code. I do not know how to display it.

Should I write another function to get the Company names from the Company table? Do I pass the list of names to the SubcontractDetail view and then somehow loop through it there?

Same questions with the SubcontractIndex view. The Index view is in table format, I’d like to have a “Company” column which has a comma separated list of the companies for each subcontract row.

[Authorize]
        public ActionResult Details(string id)
        {
           subcontract subcontract = subcontractRepository.GetSubcontract(id);

           IEnumerable<Guid> cmpny = subcontractRepository.GetSubcontractCompanies(subcontract.subcontract_id);

           if (subcontract == null)
               return View("NotFound");
           else
           {
               return View("Details", subcontract);
           }
        }

[Authorize]
    public ActionResult Index()
    {
        var subcontracts = subcontractRepository.FindAllSubcontracts().ToList();
        return View("Index", subcontracts);
    }
  • 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-13T16:01:15+00:00Added an answer on May 13, 2026 at 4:01 pm

    You have several options:
    1) You can create new class that contains subcontract & IEnumerable and pass an object of the new class to the view. This is common practice in ASP.NET MVC .

    public class MyCustomModelView
    {
        public IEnumerable<Guid> Company{ get; set; }
        public subcontract Subcontract { get; set; }
    }
    

    And in the controller:

    return View("Details", new MyCustomModelView(){
        Company = cmpny, 
        Subcontract = subcontract });
    

    And add this new type should be the type of your view.

    enter code here
    

    2) Also you can add the IEnumerable to the ViewData collection like this:

    ViewData["Company"] = cmpny;
    

    And then access it with the indexer in the view

    <% foreach(Guid id in (ViewData["Company"] as IEnumerable<Guid>)) {  %>
    ...Display names...
    <% } %>
    

    I personally will recomand you the firs because you don’t need to cast and it is cleaner

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

Sidebar

Related Questions

I'm new to developing web apps using ASP.NET MVC. In fact, I'm rather new
Completely new to asp.net mvc... completely new to web apps so bear with me...
We've been using StructureMap for Dependency Injection in our ASP.Net MvC 3 web apps
I created a web application using ASP.Net MVC 3 and EF 4.1, and I
I am new to python for web apps, and am using django for my
I'm new to Spring and Spring MVC. I developed some web-apps in ASP.NET and
I'm going to start a new project that's building web apps from scratch. I
Every new web service you create using visual studio comes with a predefined namespace
I'm building a new web app that has a requirement to generate an internal
We’ve created an ASP.NET MVC 4.0 (Beta) web site with Visual Studio 2010. The

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.