我是一名初级web开发者,这是我第一次在这里发帖。
我遇到了一个问题,内部的if语句没有被识别,而是被打印为文本。有人有解决方案吗?
编辑:找到了解决方案:无法使用Razor的foreach和if语句有条件地创建新的表行?
我遇到了一个问题,内部的if语句没有被识别,而是被打印为文本。有人有解决方案吗?
编辑:找到了解决方案:无法使用Razor的foreach和if语句有条件地创建新的表行?
@model IEnumerable<FairShare.Models.Product>
@{
ViewBag.Title = "Products";
}
<h2>
Auctions</h2>
<table border="1">
<col width="192" />
@{int i = 0;}
@foreach (var item in Model)
{
if (item.DateEnd.Subtract(DateTime.Now).TotalMinutes > -5)
{
if (i == 0)
{
<tr>
}
<td>
<a href="/ProductDetails/Index?productID=@item.ID">
<img src="Images/@item.ImageName" width="192" height="108"/>
</a>
<br />
<a href="/ProductDetails/Index?productID=@item.ID">@Html.DisplayFor(modelItem => item.ShortTitle)</a><br />
@Html.DisplayFor(modelItem => item.ShortDescription)<br />
<div style="color: red;">@Html.DisplayFor(modelItem => item.TimeLeft)</div>
<div style="color: green;">
Current bid: @Html.DisplayFor(modelItem => item.CurrentBid)</div>
</td>
i = i + 1;
if (i == 5)
{
</tr>
i = 0;
}
}
}
</table>