ASP.NET MVC Razor引擎每行显示三个数据?

MHF*_*MHF 1 asp.net-mvc razor asp.net-mvc-3

ASP.NET MVC Razor引擎中,我想在每一行中显示三个数据条目,所以我这样写:

<table width="100%" border="0" cellspacing="22" cellpadding="0" style="line-height:18px;">
    <tr>
        <td align="center" valign="top">
            <table border="0" cellspacing="0" cellpadding="0">
                <tr>
                    @{
                        int counter = 0;
                        foreach (MVCTaranehMah.Models.Folder item in ViewBag.items)
                        {
                            counter++;
                            if(counter%3 == 0)
                            {
                                <tr>
                            }
                            <td width="205" height="180" align="center" valign="top"><a href="galleryDetails?id=@item.id" ><img src="@Url.Content(item.thumb)" width="173" height="173" border="0"></a><br />
                                <p align="center" valign="top" class="header3">@item.title</p>
                            </td>
                            @if(counter%3 == 0)
                            {
                                </tr>
                            }
                        }
                    }
                 </tr>
            </table>
        </td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

但是我得到这个错误

该代码块缺少一个结束的“}”字符。确保此块中所有“ {”字符都有一个匹配的“}”字符,并且没有“}”字符被解释为标记。

有什么问题,我该怎么做?

Val*_*mas 5

我认为代码不喜欢您似乎具有未封闭的HTML标记。

放在tr之前, @:

@从另一条if语句的前面删除。

例如:

if (counter%3 == 0)
{
    @:<tr>  
}
Run Code Online (Sandbox Code Playgroud)