<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/SiteControl.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Website.SimpleRepository.Page>>" %>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
<h2>Page List</h2>
<p>
<%= Html.ActionLink("Create New", "Create") %>
</p>
<table>
<tr>
<th></th>
<th>
Display As
</th>
<th>
Layout
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%= Html.Encode(item.DisplayAs) %>
</td>
<td>
<%= Html.Encode(item.Types.Name) %>
</td>
</tr>
<% } %>
</table>
</asp:Content>
I’m having difficult accessing the item.Types.Name it returns a null exception. I have my entity data model in a separate class library. Can anyone explain why its returning a null exception and what i can do to fix this? I have seen other projects that reference related table values but cannot work out why my work differs…
Any information on this subject would be great! Thanks.
How are you querying the data?
I’ve found that the current EF setup requires me to be more explicit with magic strings than I’d like:
This of course doesn’t give you compile time checking of the foriegn keys, but it will at least return them now.