我有預約系統,其中預約日期由DateFrom
- DateTo
屬性範圍設置。現在我想將.alert
類指定給那些即將到期的預訂(1天到期)。如何僅爲當前對象設置類別
問題是,如果預訂即將過期,不僅此預訂有.alert
課程設置,而且還包括所有其他預訂,所以所有<tr>
都是紅色,即使只有一個預定。如何將它僅綁定到當前的保留?
條件
foreach(Reservation r in res)
{
bool varovani;
if (r.DateTo.AddDays(-1).Day <= DateTime.Now.Day)
{
varovani = true;
}
else
{
varovani = false;
}
ViewBag.Varovani = varovani;
}
表中查看
<tbody>
@foreach (Reservation r in Model)
{
string alertClass = "";
if (ViewBag.Varovani == true)
{
alertClass = "danger";
}
else
{
alertClass = "";
}
<tr class="@alertClass">
<td>@r.Reserved.Id</td>
<td>@r.Name</td>
<td>@r.DateFrom</td>
<td>@r.DateTo</td>
<td>
@Ajax.ActionLink("Detail", "Detail", "Skies", new { id = r.Reserved.Id }, new AjaxOptions() { InsertionMode = InsertionMode.Replace, UpdateTargetId = "modalContent", OnBegin = "openModalWindow" })
</td>
<td>
@Html.ActionLink("Edit", "Edit", "Reservation", new { id = r.Id }, null)
@Html.ActionLink("Delete", "Delete", "Reservation", new { id = r.Id }, new { onclick = "return confirm('Přejete si opravdu smazat tuto výpujčku? " + r.Name + "');" })
</td>
</tr>
}
</tbody>
您正在根據ViewBag項目的值設置類,這意味着它最終會發生在所有事情上。您需要根據該預訂進行設置。我會將一個屬性添加到'Reservation'視圖模型,然後在那裏檢測它。 – nurdyguy