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>
See Question&Answers more detail:os