[英]Parsing error in cshtml file in ASP.NET MVC4
In the view, I am trying to display at most 5 images in a row. 在视图中,我试图连续显示最多5个图像。 The idea is to introduce a new row by using the
</tr><tr>
html tags to close the present row and start a new one as shown below, but this gives a Parser error. 我们的想法是通过使用
</tr><tr>
html标记来引入一个新行来关闭当前行并开始一个新行,如下所示,但这会产生一个Parser错误。
Parser Error Message: The code 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.
确保此块中的所有“{”字符都有匹配的“}”字符,并且没有任何“}”字符被解释为标记。
How can I correct this? 我怎么能纠正这个?
<table>
<tr>
@{
int indx = 0;
foreach(var item in Model) {
indx++;
<td>
<a href ="@Url.Action("ShowPic", "ViewPhotos", new { id = item.ID })">
<img src="@String.Format("data:image/jpg;base64,{0}", Convert.ToBase64String(item.Image))" />
</a>
<br />
@Html.DisplayFor(modelItem => item.Caption)
</td>
if(indx%5==0) {
</tr><tr><!--Error here-->
}
}
}
</tr>
</table>
Thanks. 谢谢。
Try adding this to the row in question 尝试将此添加到相关行
@: </tr><tr><!--Error here-->
Because you are wrapping it in a HTML tag element, Razor cannot determine that the content within the if
is the start of a content block. 因为您将它包装在HTML标记元素中,所以Razor无法确定
if
中的内容if
是内容块的开头。 By using @:
we are indicating that the contents of the statement should be treated as content. 通过使用
@:
我们指出语句的内容应该被视为内容。
Your first <tr>
and last </tr>
is outside of the scope of it's opening/closing tag: 您的第一个
<tr>
和最后一个</tr>
超出了它的开始/结束标记的范围:
<table>
@{
<tr>
int indx = 0; foreach (var item in Model) { indx++;
<td>
<a href ="@Url.Action("ShowPic", "ViewPhotos", new { id = item.ID })">
<img src="@String.Format("data:image/jpg;base64,{0}", Convert.ToBase64String(item.Image))" />
</a>
<br />
@Html.DisplayFor(modelItem => item.Caption)
</td>
if(indx%5==0) {
</tr>
<tr>
} }
</tr>
}
</table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.