【发布时间】:2019-06-18 16:11:18
【问题描述】:
我正在使用 MVC .net 应用程序编写学校信息系统。但我似乎无法避免在我的部分中显示 null
我在我的控制器和我的视图中尝试了一个 If 语句,这样它就不会显示除了毕业的人之外的任何东西 In this picture I'm showing the page where I want to show only the people with the gratuated status
在控制器中:
public ActionResult Index()
{
var graduates = db.Graduated_Students;
return View(graduates.ToList());
}
在模型中:
public partial class Graduated_Students
{
public int ID { get; set; }
public int CohortId { get; set; }
public string Name { get; set; }
public string FullName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string ContractStatus { get; set; }
public string DepositStatus { get; set; }
public string GraduationStatus { get; set; }
}
在视图中:
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ID)
</td>
<td>
@Html.DisplayFor(modelItem => item.FullName)
</td>
<td>
@Html.DisplayFor(modelItem => item.CohortId)
</td>
<td>
</td>
<td>
</td>
<td>
@Html.DisplayFor(modelItem => item.GraduationStatus)
</td>
【问题讨论】:
-
究竟什么是 null,您认为什么是“部分”?
-
@cwharris 我刚刚编辑了问题,是不是更清楚了?
标签: .net razor model-view-controller