这是我的模型:
public class Stages
{
public int Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
public string Des { get; set; }
public string View_Count { get; set; }
}
我的控制器:
public ActionResult ViewStages()
{
return View();
}
我的观点:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<IEnumerable<Project.Models.Stages>>" %>
//Some Code...
<% foreach (var item in Model)
{ %>
<tr>
<td>
<%: Html.DisplayFor(modelItem => item.Code)%>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Name)%>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Des)%>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.View_Count)%>
</td>
<td>
<%: Html.ActionLink("Edit", "Edit", new { id = item.Id })%> |
<%: Html.ActionLink("Details", "Details", new { id = item.Id })%> |
<%: Html.ActionLink("Delete", "Delete", new { id = item.Id })%>
</td>
</tr>
<% }%>
</table>
</asp:Content>
而且我总是得到这个错误:对象引用未设置为对象的实例。并且在到达 foreach 循环时发生错误。问题是什么?