I am trying to get NerdDinner to work, and having a bit of trouble.
I have quick watched at the point where the actionResult for index happens, and seen that the items from the dinnerRepository are on the right side of the asignment operator.
However it seems when I step through to the next line of the code, dinners, which is passed to the view, does not contain the recordset.
Could anyone point me out where I am going wrong.
The result is that the page renders perfectly, but no records are shown.
namespace NerdDinner.Controllers
{
public class DinnersController : Controller
{
DinnerRepository dinnerRepository = new DinnerRepository();
// GET: /Dinners/
public ActionResult Index()
{
var dinners = dinnerRepository.FindUpcomingDinners().ToList();
return View("Index", dinners);
}
// GET: /Dinners/Details/2
public ActionResult Details(int id)
{
Dinner dinner = dinnerRepository.GetDinner(id);
if (dinner == null)
return View("NotFound");
else
return View("Details", dinner);
}
}
}
And here is the view code as well
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<NerdDinner.Models.Dinner>>" %>
<asp:Content ID="Main" ContentPlaceHolderID="MainContent" runat="server">
<h2>Upcoming Dinners</h2>
<ul>
<% foreach (var dinner in Model)
{%>
<li>
<%= Html.Encode(dinner.Title)%>
on
<%= Html.Encode(dinner.EventDate.ToShortDateString())%>
@
<%= Html.Encode(dinner.EventDate.ToShortTimeString())%>
</li>
<% } %>
</ul>
</asp:Content>
And the model code as well
public class DinnerRepository { private NerdDinnerDataContext db = new NerdDinnerDataContext();
// Query Methods
public IQueryable<Dinner> FindAllDinners()
{
return db.Dinners;
}
public IQueryable<Dinner> FindUpcomingDinners()
{
return from dinner in db.Dinners
where dinner.EventDate > DateTime.Now
orderby dinner.EventDate
select dinner;
}
public Dinner GetDinner(int id)
{
return db.Dinners.SingleOrDefault(d => d.DinnerID == id);
}
// Insert/Delete Methods