I am learning MVC with Razor and have a simple question (I think). I am having trouble displaying the contents of a model in the view and am not sure why.
My view is a .cshtml page.
I am passing a model to it that is of type IEnumerable
I cannot get the ‘foreach’ statement to run in the below view. Interesting the <% characters are not coloured yellow in Visual Studio so I think I may have missed something. Any ideas? Here is my view code…
@model IEnumerable<HERE_MVC.Models.CheckIn>
@{
ViewBag.Title = "Home";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Home - Main page</h2>
<% foreach (var checkIn in Model.CheckIn){ %>
<li><%: checkIn.ID %></li>
<% } %>
And my controller code looks like this…
public ActionResult Home(string lat, string lon)
{
ViewBag.Message = "Welcome to HERE!";
HEREModel m = new HEREModel();
var v1 = m.GetEntitiesByLatLon(lat, lon);
return View(v1);
}
Thank you in advance, I’ve been trying to work this out for a while but with no luck.
Brush up on your Razor syntax — Razor doesn’t use bee stings (<%). Try this: