【发布时间】:2014-01-28 18:17:13
【问题描述】:
我在 MVC 中用 Razor 语法做一个简单的 for 循环:
@for (int i = 0; i < Model.ProductViewModels.Count; i++)
{
if (i%2 == 0)
{
<div class="row">
}
<div class="col-md-4">
<a href="/product?id=@Model.ProductViewModels[i].Id">@Model.ProductViewModels[i].Title - @Model.ProductViewModels[i].Isbn13
<br />
<img src="@Model.ProductViewModels[i].ImageUrl" />
</a>
</div>
@if (i%2 == 0)
{
</div>
}
}
在我看来,这似乎是相当合法的代码,但它不起作用!
我得到错误:
Meddelelse om parserfejl: The for block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
错误截图:
有什么想法吗? :) 谢谢
【问题讨论】:
-
对于使用助手类的(更好的)解决方案,请参阅此答案:stackoverflow.com/questions/24385181/…
标签: asp.net-mvc asp.net-mvc-4 razor