ASP.NET MVC 3 Razor Nested foreach with if statements

时间:2023-03-09 08:08:15
ASP.NET MVC 3 Razor Nested foreach with if statements
         You need to write code this way.  @Html.Raw("<tr>")
Copy the below code and paste it into your view. it will work. @model IEnumerable<FairShare.Models.Product> @{
ViewBag.Title = "Products";
}
<h2>
Auctions</h2>
<table border="">
<col width="" /> @{int i = ;}
@foreach (var item in Model)
{
if (item.DateEnd.Subtract(DateTime.Now).TotalMinutes > -)
{
if (i == )
{
@Html.Raw("<tr>")
}
<td>
<a href="/ProductDetails/Index?productID=@item.ID">
<img src="Images/@item.ImageName" width="" height=""/>
</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 + ;
if (i == )
{
@Html.Raw("</tr>")
i = ;
}
}
} </table>