当我尝试在 razor 中使用 if 子句时遇到错误,如下所示:
“@”字符后出现意外的“if”关键字。
@foreach (var item in Model) {
@if (item.Country != "No Country")
{
<li>@Html.ActionLink(item.CountryWithCount, "IndexByProv", "EventInfo", new { country = item.Country }, null)</li>
为什么我收到此错误?
最佳答案
您不需要@
,因为您已经位于代码块内。
@foreach (var item in Model) {
if (item.Country != "No Country")
{
<li>something</li>
}
}
关于asp.net-mvc-3 - 在 razor 中使用 @if 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11799533/