Note that there are some explanatory texts on larger screens.

plurals
  1. PONerd dinner, possibly an extreme noob question, list dinners
    text
    copied!<p>I am trying to get <a href="http://nerddinner.com/" rel="nofollow noreferrer">NerdDinner</a> to work, and having a bit of trouble.</p> <p>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.</p> <p>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.</p> <p>Could anyone point me out where I am going wrong.</p> <p>The result is that the page renders perfectly, but no records are shown.</p> <pre><code>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); } } } </code></pre> <p>And here is the view code as well</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;IEnumerable&lt;NerdDinner.Models.Dinner&gt;&gt;" %&gt; &lt;asp:Content ID="Main" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;h2&gt;Upcoming Dinners&lt;/h2&gt; &lt;ul&gt; &lt;% foreach (var dinner in Model) {%&gt; &lt;li&gt; &lt;%= Html.Encode(dinner.Title)%&gt; on &lt;%= Html.Encode(dinner.EventDate.ToShortDateString())%&gt; @ &lt;%= Html.Encode(dinner.EventDate.ToShortTimeString())%&gt; &lt;/li&gt; &lt;% } %&gt; &lt;/ul&gt; &lt;/asp:Content&gt; </code></pre> <p>And the model code as well</p> <p>public class DinnerRepository { private NerdDinnerDataContext db = new NerdDinnerDataContext();</p> <pre><code> // Query Methods public IQueryable&lt;Dinner&gt; FindAllDinners() { return db.Dinners; } public IQueryable&lt;Dinner&gt; FindUpcomingDinners() { return from dinner in db.Dinners where dinner.EventDate &gt; DateTime.Now orderby dinner.EventDate select dinner; } public Dinner GetDinner(int id) { return db.Dinners.SingleOrDefault(d =&gt; d.DinnerID == id); } // Insert/Delete Methods </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload