码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET MVC 3 Razor Nested foreach with if statements

时间:2015-05-03 20:19:59      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

         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>

 

ASP.NET MVC 3 Razor Nested foreach with if statements

标签:

原文地址:http://www.cnblogs.com/niaowo/p/4474506.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!