title: Passing data from a controller to the view in ASP.NET MVC
body: <p>I have the following in my controller (HomeController.cs) which generates a Bikes variable that I'm trying to pass into the view (Index.cshtml):</p>
  
  <pre><code>public string xmlPath = HostingEnvironment.MapPath("~/App_Data/bikes.xml");
  
  public ActionResult Index()
  {
      // get the most recent 20 records
      XDocument xml = XDocument.Load(xmlPath);
  
      var bikes = from b in xml.Descendants("Photo")
              select new
              {
                  date = (DateTime)b.Element("Date"),
                  staffno = (Int32)b.Element("StaffNo"),
                  file = (string)b.Element("File"),
                  crimeref = (string)b.Element("CrimeRef")
              };
  
      var Bikes = bikes.ToList();
  
      return View(Bikes);
  }
  </code></pre>
  
  <p>I now want to loop through the results and display them on the page using Razor using the following code:</p>
  
  <pre><code>@foreach (var bikes in Bikes))
  { 
      &lt;tr&gt;
          &lt;td&gt;@(bikes.date)&lt;/td&gt;
          &lt;td&gt;@(bikes.staffno)&lt;/td&gt;
          &lt;td&gt;@(bikes.file)&lt;/td&gt;
          &lt;td&gt;@(bikes.crimeref)&lt;/td&gt;
      &lt;/tr&gt;
  }
  </code></pre>
  
  <p>However, despite passing the Bikes variable into the View() command in the controller, the Bikes list is not accessible from within my view.</p>
  
  <p>Any suggestions would be very welcome, thank you :)</p>