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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:58:33+00:00 2026-06-05T12:58:33+00:00

So I created a project to test DI in MVC 4. Yeah, that was

  • 0

So I created a project to test DI in MVC 4. Yeah, that was the easy part. I have a controller that looks like this.

public class CompanyManagementController : Controller
{
     private ICompanyService companyService;

     public CompanyManagementController(ICompanyService companyService)
     {
         this.companyService = companyService;
     }

     public ActionResult Index()
     {
         return View(companyService.GetCurrentCompanies());
     }
}

What I can’t figure out is how to tell the view Index.cshtml that I have this List that I am returning to it. When I have just a POCO it’s easy. I did this

[HttpGet]
public ActionResult Create()
{
    var company = new Company();
    return View(company);
}

[HttpPost]
public ActionResult Create(Company company)
{
    using(var context = new InventoryContext())
    {
        context.Companies.Add(company);
        context.SaveChanges();
    }
    return View("Create");
}

That was super easy because I just said

@model MvcInventoryManager.Models.Company

in the Create.cshtml file.

Any hints? What I want to do is be able to loop through the list of companies that get returned.

Thanks!

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

    What is the return type of companyService.GetCurrentCompanies()? That would be the type you’d want to use for binding the Model in the view. For example, if the type is IEnumerable<Company> then in your view you would declare this:

    @model IEnumerable<MvcInventoryManager.Models.Company>
    

    That way the type of the Model property would match what’s being passed to the view and you could loop through the Model:

    foreach (var company in Model)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To simplify this test case, I created a new default .NET MVC project in
I have created a little test project to try to resolve a problem I
I installed JDeveloper 11.1.1.6 and opened a simple test project that was originally created
I have created a unit test in my c# project which builds into a
I'm using NInject with NInject.Web.Mvc. To start with, I've created a simple test project
I have created one Android Project with Ant build. And also created Test Project
i created an MVC Project for test on another PC last night it worked
I created a simple Asp.net MVC 4 application I created the NUnit test project
My main project is an android library. I have created a test project with
I created a empty test project (static library type) with enabling the unit test.

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.