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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:07:09+00:00 2026-06-11T14:07:09+00:00

I have a follow up question on the accepted answer given here: Two models

  • 0

I have a follow up question on the accepted answer given here: Two models in one view in ASP MVC 3

I have three models, Types, Causes, Locations that I would like to list the contents of in one view. Based on the answer in the link above I made a new model that combined the that looks like this:

public class Combined
    {
        public IEnumerable<Place> Place { get; set; }
        public IEnumerable<Type> Type { get; set; }
        public IEnumerable<Cause> Cause { get; set; }
    }

I made it IEnumerable<> because as I understand it, thats what I want when I just want to list the contents of these models in a foreach loop. Then I made this controller for the view:

[ChildActionOnly]
    public ActionResult overSightHeadings()
    {
        Combined Combined = new Combined();
        return View(Combined);
    }

And finally the view (I was just trying to list from one of the tables first):

@model mvcAvvikelser.Models.Combined
@{
    Layout = null;
}
<tr>
@foreach (var Type in Model.Type)
{
    <th> @Html.DisplayTextFor(ModelItem => Type.Name)</th>
}
</tr>

The problem with this code is that it throws up a null exception when the foreach code starts.

System.NullReferenceException: Object reference not set to an instance of an object.

So I am not entirely sure what I am doing wrong here, should it not be an IEnumerable, have I initialized the model incorrectly in the controller?

  • 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-11T14:07:10+00:00Added an answer on June 11, 2026 at 2:07 pm

    Should be this

    [ChildActionOnly]
    public ActionResult overSightHeadings()
    {
        Combined combined = new Combined();
        combined.Types = new List<Type>();
        combined.Causes = new List<Cause>();
        combined.Places = new List<Place>();
    
        return View(Combined);
    }
    

    Note that I have changed the property names to plural. That defines your property as collection.

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

Sidebar

Related Questions

PHP mysql database I have created a follow on question to this one here
I have the relationship follow as: class Question(models.Model): content = models.CharField(max_length=128) class Answer(models.Model): content
I have a follow-up question to this one . I created a new form,
I have a follow up question to this one . Now that I have
I have a follow-up question regarding an issue I previously had on SO here
i have an html table in my asp.net mvc view an i am running
I have just realized that the answer I accepted for my previous question was
I have a follow up question to Sasha's answer of my earlier question at
I have a follow up question to Given a private key, is it possible
I have a follow up question to this question . Is it possible to

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.