Index.aspx View won't display dynamic data

Jul 25, 2011 at 12:05 AM

This is what my view looks like for Index.aspx, but it isn't displaying the content of the Dinners table as I would expect.  I inserted a Model.Count() and it returns 0, 
so it's not picking up NerdDinner.Models.Dinners. Since the Dinners class is generated by the .net framework, there isn't any source code I can look at, is there?

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<NerdDinner.Models.Dinners>>" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Index </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Index</h2> <table> <tr> <th></th> <th> DinnerID </th> <th> Title </th> <th> EventDate </th> <th> Description </th> <th> HostedBy </th> <th> ContactPhone </th> <th> Address </th> <th> Country </th> <th> Latitude </th> <th> Longitude </th> </tr> <tr> <%= Model.Count() %> </tr> <% foreach (var item in Model) { %> <tr> <td>test <%= Html.ActionLink("Edit", "Edit", new { id=item.DinnerID }) %> | <%= Html.ActionLink("Details", "Details", new { id=item.DinnerID })%> | <%= Html.ActionLink("Delete", "Delete", new { id=item.DinnerID })%> </td> <td> <%= Html.Encode(item.DinnerID) %> </td> <td> <%= Html.Encode(item.Title) %> </td> <td> <%= Html.Encode(String.Format("{0:g}", item.EventDate)) %> </td> <td> <%= Html.Encode(item.Description) %> </td> <td> <%= Html.Encode(item.HostedBy) %> </td> <td> <%= Html.Encode(item.ContactPhone) %> </td> <td> <%= Html.Encode(item.Address) %> </td> <td> <%= Html.Encode(item.Country) %> </td> <td> <%= Html.Encode(String.Format("{0:F}", item.Latitude)) %> </td> <td> <%= Html.Encode(String.Format("{0:F}", item.Longitude)) %> </td> </tr> <% } %> </table> <p> <%= Html.ActionLink("Create New", "Create") %> </p> </asp:Content>

Jul 28, 2011 at 9:20 PM

I found a solution.  The problem was in the controller--I wasn't setting model correctly.