@Eranga上記の回答とコメントに感謝します。私はそれを次のようにして動作させました、
コントローラ:
panelViewModel.Panels = _panelRepository.GetPanels()
.Where(p => p.PanelApplicationForms.Count > 0
&& p.PanelApplicationForms
.Any(f => f.IsPublish
&&
f.PanelApplicationFormVersions.OrderByDescending(v => v.VersionNumber).
First().DueDate >= DateTime.Today
&& f.PanelApplicationFormVersions.Count > 0
)
&& p.PanelApplicationForms != null)
.OrderBy(t => t.Title);
意見:
@foreach (var panelApplicationFormItem in panelItem.PanelApplicationForms.Where(panelApplicationFormItem => panelApplicationFormItem.IsPublish))
{
var panelApplicationFormVersion = panelApplicationFormItem.PanelApplicationFormVersions.OrderByDescending(v => v.VersionNumber).First();
if (panelApplicationFormVersion.DueDate >= DateTime.Today)
{
<tr>
<td>
@Html.DisplayFor(modelItem => panelApplicationFormItem.Title)
</td>
<td class="span2">
@if (panelApplicationFormItem.PanelApplicationFormVersions.Count > 0)
{
@Html.DisplayFor(modelItem => panelApplicationFormVersion.DueDate)
}
</td>
<td class="span2">
@{
//var isApplicationAlreadyExist = panelApplicationFormVersion.Id.IsApplicationAlreadyExist()
}
@if (panelApplicationFormVersion != null)
{
<a href="~/Application/Apply/@panelApplicationFormVersion.Id?versionNumber=@panelApplicationFormVersion.VersionNumber" class="btn">Apply</a>
}
else
{
<a href="#" class="btn">Sum</a>
@*<p>No versions available to apply</p>*@
}
</td>
</tr>
}
}