title: How to merge two different models in one model and show output in one view?
body: <p>Here is my model</p>
  
  <pre><code>    {
          public int Id { get; set; }
          public int? MainSurveyId { get; set; }
          public string Question { get; set; }
          public DateTime? DateCreated { get; set; }
          public string CreatedBy { get; set; }
          public string Status { get; set; }
          public IList&lt;xxAnswer&gt; answers { get; set; }
      }
  </code></pre>
  
  <p>This is my controller, notice that I separated the <code>var question</code> and <code>var answer</code></p>
  
  <pre><code> [HttpPost]
          public IActionResult CompareCompetitors(string[] comps, int Surveyid)
          {
             var model = new CompareCompetitorAnswers();
             foreach( var item in comps){
                 model.competitorNames.Add( new xxCompetitor() { CompetitorName = item} );
             }
  
              var questions = _context.SurveyQuestions.ToList().Where(x =&gt; x.MainSurveyId == Surveyid);
              foreach (var q in questions){
                  model.questions.Add(new xxQuestion { Question = q.Question});
              }
  
               var answers = _context.SurveyCompetitorAnswer.ToList().Where(x =&gt; x.MainSurveyId == Surveyid);
              foreach (var a in answers){
                  model.answers.Add(new xxAnswer { Answer = a.Answer});
              }
  
  
              return View(model);
              //return string.Join(",", comps); // check if it works with this. ph wait. i think correct. sorry. i will try now.
          }
  </code></pre>
  
  <p>Here is my view but it shows an error in <code>@foreach (var a in q.answers)</code>.</p>
  
  <pre><code> &lt;tbody&gt;
           @foreach (var q in Model.questions)
              {
                  &lt;tr&gt;
                      &lt;td scope="row"&gt;
                          @q.Question
                      &lt;/td&gt;
                      @foreach (var a in q.answers)
                      {
                          &lt;td scope="row"&gt;
                              @a.Answer
                          &lt;/td&gt;    
                      }
  
  
                  &lt;/tr&gt;
              }
          &lt;/tbody&gt;
  </code></pre>
  
  <p>I want the answers to be posted beside the results. They are in different database tables. But it output errors at <code>@foreach (var a in q.answers)</code>.</p>