【发布时间】:2009-05-18 12:54:15
【问题描述】:
<%@ 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>
我很难访问 item.Types.Name 它返回一个空异常。我在一个单独的类库中有我的实体数据模型。谁能解释为什么它返回一个空异常以及我能做些什么来解决这个问题?我见过其他引用相关表值的项目,但无法弄清楚为什么我的工作有所不同......
任何关于这个主题的信息都会很棒!谢谢。
【问题讨论】:
-
请在控制器操作中发送代码。
标签: asp.net-mvc entity-framework