Razor - Unexpected "foreach" keyword after "@" character
Posted
by
Jaco Pretorius
on Stack Overflow
See other posts from Stack Overflow
or by Jaco Pretorius
Published on 2011-02-09T14:40:22Z
Indexed on
2011/02/09
15:25 UTC
Read the original article
Hit count: 3607
asp.net-mvc-3
|Razor
I have a partial view done in razor. When I run it I get the following error - it seems like Razor gets stuck into thinking I'm writing code everywhere.
Unexpected "foreach" keyword after "@" character. Once inside code, you do not need to prefix constructs like "foreach" with "@"
Here is my view
@model IEnumerable<SomeModel>
<div>
@using(Html.BeginForm("Update", "UserManagement", FormMethod.Post)) {
@Html.Hidden("UserId", ViewBag.UserId)
@foreach(var link in Model) {
if(link.Linked) {
<input type="checkbox" name="userLinks" value="@link.Id" checked="checked" />@link.Description<br />
} else {
<input type="checkbox" name="userLinks" value="@link.Id" />@link.Description<br />
}
}
}
</div>
© Stack Overflow or respective owner