Reputation: 5477
I've spent 45mins looking for the missing closing "}" and I can't find it. I rewrote the code and I still get this error. What am I doing wrong?
Parser Error Message: The foreach 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.
Line 9: @foreach (var item in Model) {
@foreach (var item in Model) {
int checkId = item.Id;
if (item.ReplyId == checkId){
<div>
<h4>Forum</h4>
<hr />
<div class="panel panel-default">
<div class="panel-heading">
@Html.DisplayFor(modelItem => item.Title)
</div>
<div class="panel-body">
@Html.DisplayFor(modelItem => item.Body)
</div>
</div>
}
}
@foreach(var item2 in Model)
{
if(item2.ReplyId == checkId){
<div class="panel panel-default">
</div>
<div class="panel-body">
@Html.DisplayFor(modelItem => item2.Body)
</div>
</div>
}
}
<p>
@if (Request.IsAuthenticated)
{
string user = item.User;
if (User.Identity.Name == user)
{
<p>@Html.ActionLink("Edit", "Edit", new { id = checkId }) |</p>
<p>@Html.ActionLink("Reply", "Reply", new { id = checkId }) |</p>
}
@Html.ActionLink("Back to List", "Index")
}
Upvotes: 1
Views: 2547
Reputation: 40393
It's your unclosed div
in the first block, and an extra closing /div
in your second block. Razor is very picky about that kind of thing.
Once you fix those, you'll run into some other syntax issues, like item
not being defined in your third block, but you should be able to deal with those.
Upvotes: 0
Reputation:
your missing a closing "/div" In this code: @Html.DisplayFor(modelItem => item2.Body). That might be why it errors out.
Upvotes: 1
Reputation: 1751
You must wrap long closures in @{ } brackets. I believe this is your issue:
@if (Request.IsAuthenticated) {
//...
}
Try:
@{
if(Request.IsAuthenticated) {
//...
}
}
Wrapping all html/text elements with <text></text>
tags
Upvotes: 2