title: Foreach with data from the viewbag
body: <p>Below is my code.</p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public class ShiftsModel
  {
      public string UID { get; set; }
      public string Date { get; set; }
      public string Time { get; set; }
      public string Location { get; set; }
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public class HomeController : Controller
  {
      public string xmlPath = HostingEnvironment.MapPath("~/App_Data/data.xml");
  
      public ActionResult Index()
      {
          XDocument xml = XDocument.Load(xmlPath);
  
          var shifts = (from b in xml.Descendants("Shift")
                        select new ShiftsModel
                       {
                           UID = (string)b.Attribute("UID"),
                           Date = (string)b.Element("Date"),
                           Time = (string)b.Element("Time"),
                           Location = (string)b.Element("Location")
                       }).ToList();
  
          return View(shifts);
      }
  
  }
  </code></pre>
  
  <p>I'd now like to reference this in my Index.cshtml file like so:</p>
  
  <pre><code>@foreach(var shift in (List&lt;object&gt;ViewBag.shifts)) {
  &lt;tr&gt;
      &lt;td&gt;
          &lt;input type="text" id="date" name="date" placeholder="Date" value="@(ViewBag.date)" }&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;input type="text" id="time" name="time" placeholder="Shift time" value="@(ViewBag.time)" }&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;input type="text" id="location" name="location" placeholder="Location" value="@(ViewBag.location)" }&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  }
  </code></pre>
  
  <p>However, I get an error on the <code>List&lt;object&gt;ViewBag.shifts</code> line saying: </p>
  
  <blockquote>
    <p>Represents a strongly typed list of objects that can be accessed by
    index.</p>
  </blockquote>
  
  <p>Any suggestions as to what I'm doing wrong please? Thank you :)</p>