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):
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);
}
I now want to loop through the results and display them on the page using Razor using the following code:
@foreach (var bikes in Bikes))
{
<tr>
<td>@(bikes.date)</td>
<td>@(bikes.staffno)</td>
<td>@(bikes.file)</td>
<td>@(bikes.crimeref)</td>
</tr>
}
However, despite passing the Bikes variable into the View() command in the controller, the Bikes list is not accessible from within my view.
Any suggestions would be very welcome, thank you :)