title: Passing a List to View from Controller in .NET
body: <p>I am just trying to pass a List and display it dynamically in a table in the View. I have a Homepage Model and Homepage controller and the variables are being set right, but I can't figure out how to pass it to the view.</p>
  
  <p>My model looks like this:</p>
  
  <pre><code> public class HomePageModel
   {
      [Display(Name = "First Name")]
      public string FirstName { get; set; }
      [Display(Name = "Last Name")]
      public string LastName { get; set; }
      [Display(Name = "ExtNum")]
      public string ExtNum { get; set; }
      [Display(Name = "PhoneDisplay")]
      public List&lt;PhoneDisplay&gt; PhoneDisplay { get; set; }
   }
  </code></pre>
  
  <p>and this is the controller:</p>
  
  <pre><code> public ActionResult Homepage(HomePageModel HpModel)
      {
          ViewBag.Welcome = "Welcome: ";
          ViewBag.FirstName = HpModel.FirstName;   
          ViewBag.LastName = HpModel.LastName; 
          ViewBag.Extlbl = "Extension: ";
          ViewBag.Ext = HpModel.ExtNum;
          ViewBag.Todaylbl = "Today:";
          ViewBag.Today = DateTime.Now;
          DBOps ops = new DBOps();
          HpModel.PhoneDisplay = ops.getDisplayInfo(HpModel.ExtNum);
          return View(HpModel);
      }
  </code></pre>
  
  <p>PhoneDisplay is a list that contains a line index, a description string and a 4 digit number. Each user will have at least 1 item in this list and maximum 6. I was able to pass the other parameters and display them in the view but I can't find a way to pass the list and display that dynamically.</p>
  
  <p><strong>EDIT</strong>
  I made it this far but still can't find the list items.</p>
  
  <pre><code>    @model AxlMVC.Models.HomePageModel
      &lt;table&gt;
      &lt;caption style="font-weight:bold"&gt;Your Phone Information&lt;/caption&gt;    
      &lt;tr&gt;
          &lt;th&gt;Line Index&lt;/th&gt;
          &lt;th&gt;Display&lt;/th&gt;
          &lt;th&gt;Extension Number&lt;/th&gt;
      &lt;/tr&gt;
      @{
      foreach (var item in Model.PhoneDisplay) //problems here
      {
       &lt;tr&gt;
          &lt;td&gt;
               @Html.Display(item.numplanindex)
          &lt;/td&gt;
          &lt;td&gt;
               @Html.Display(item.display)
          &lt;/td&gt;
          &lt;td&gt;
               @Html.Display(item.dnorpattern)
          &lt;/td&gt;
       &lt;/tr&gt;
      }
   }
      &lt;/table&gt;
  </code></pre>
  
  <p><strong>EDIT</strong>
  I debugged the cshtml file and the items in the foreach loop are being passed just fine too, but the table is not showing on the page and neither are the items all I can see is the caption and the headers for each column</p>
  
  <p><img src="https://i.stack.imgur.com/6GcNZ.png" alt="enter image description here"></p>