2 回答
TA贡献1803条经验 获得超3个赞
我不确定我是否做对了,但我想你需要的是这个,每次你循环你的位置时,你应该再次循环你的日期,然后计算或求和发生计数(取决于你的系统设计我没有't get it)并显示它。您无需担心单元格顺序,因为您总是在同一天循环,因此它们将对齐第一个 col 始终是第一天,依此类推。还请仔细检查我使用的条件,我不确定它是否正确,但无论如何这是方法。
<!-- Loop through locations -->
@foreach (var weighLocation in Model.WeighLocations)
{
<tr>
<td>@weighLocation.Weigh_Location</td>
<!-- loop through current days week days for each location-->
@foreach(var currentDay in Model.CurrentWeekDates)
{
<!-- Here you count the rows or maybe sum the OccurenceCount I am not sure how you design it, I used count but you can use sum OccurenceCount -->
<td>
<!-- Compare the location id and the teuForm date -->
@Model.WeighAssociations.Where(e => e.WeighLocationId == weighLocation.Id && e.tbl_TEUForm.EventDate == currentDay).Count()
</td>
}
</tr>
}
TA贡献1847条经验 获得超11个赞
我已经想通了。
在我看来,我将table tbody代码编辑为:
<tbody>
@foreach (var weighLocation in Model.WeighLocations)
{
<tr>
<td>@weighLocation.Weigh_Location</td>
@foreach (var date in Model.CurrentWeekDates)
{
if (Model.WeighAssociations.Any(x => x.tbl_TEUForm.EventDate == date && x.WeighLocationId == weighLocation.ID))
{
<td>@Model.WeighAssociations.Single(x => x.tbl_TEUForm.EventDate == date && x.WeighLocationId == weighLocation.ID).OccurenceCount</td>
}
else
{
<td>0</td>
}
}
</tr>
}
</tbody>
- 2 回答
- 0 关注
- 109 浏览
添加回答
举报