zoukankan      html  css  js  c++  java
  • 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="1">
                    <col width="192" />
    
                    @{int i = 0;}
                        @foreach (var item in Model)
                        {
                            if (item.DateEnd.Subtract(DateTime.Now).TotalMinutes > -5)
                            {
                                if (i == 0)
                                {
                                   @Html.Raw("<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)
                                {
                                   @Html.Raw("</tr>")
                                    i = 0;
                                }
                            }
                        }
    
                </table>
  • 相关阅读:
    git连接远程分支
    如何找N个数中第i小的数
    DeconvNet
    深度学习中的Internal Convariate Shift (ICS)
    BA算法解决p-中位问题
    蚁群算法
    蝙蝠算法初探
    轨迹压缩之Douglas-Peucker算法之C++实现
    遗传算法---编程小试
    NYOJ 1000
  • 原文地址:https://www.cnblogs.com/niaowo/p/4474506.html
Copyright © 2011-2022 走看看