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 關注
- 132 瀏覽
添加回答
舉報