mardi 4 août 2015

Razor views - @if statement compilation error

Razor views scaffolded by Visual Studio contains an "actions" element with links separated by pipe character (|)

<td>
   @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
   @Html.ActionLink("Details", "Details", new { id = item.Id }) |
   @Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>

I would like to render those links conditionally:

<td>
    @if (item.IsSuccess)
    {
        @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
        @Html.ActionLink("Details", "Details", new { id = item.Id }) |
        @Html.ActionLink("Delete", "Delete", new { id = item.Id })
    }
</td>

The code above seems correct in Visual Studio, however execution results in an Compilation Error

Compilation Error
Description: An error occurred during the compilation of a resource required    
to service this request. Please review the following specific error details and
modify your source code appropriately.

Compiler Error Message: CS1513: Expected sign }.

Source Error:


Line 491:        }
Line 492:    }
Line 493:}

Can you please point me where is the problem? The code seems syntactially correct.

Aucun commentaire:

Enregistrer un commentaire