I am trying to write below simple code in razor page but it gives always error.
( @gallery.Images.Count images ) // expect : ( 23 images )
But strangely below code works
(@Model.RateCount rates)
I am getting compilation error not runtime exception
Full cshtml page is at below.
@using Something.UI.Models.ViewModels
@model List<ImageGalleryUI>
<div class="albumlist">
@foreach (ImageGalleryUI gallery in Model)
{
<a href="@Html.ActionLinkRef(gallery.DisplayAction)">
<img src="@gallery.AlbumImageSrc" alt="@gallery.AlbumName" width="150px"/>
</a>
@Html.ActionLink(gallery.DisplayAction)
( @gallery.Images.Count images )
}
</div>
And here is 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: CS1646: Keyword, identifier, or string expected after verbatim specifier: @
Source Error:
Line 9: </a>
Line 10: @Html.ActionLink(gallery.DisplayAction)
Line 11: ( @{gallery.Images.Count} images )
Line 12: }
Line 13: </div>
If you haven’t done anything like this at the top
Then gallery does not exist.
Are you sure you do not mean
@Model.gallery.Images.Count?EDIT
Try replacing
With
Should work out just fine. Problem is that Razor is interpreting ( as part of the code, and not as part of the output. Put @: to let Razor know that what comes on this line is output that should go into the response stream.