Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: Additional '@' characters in Razor code blocks break compilation in Razor v2. [587]

$
0
0
1. In Visual Studio, create a Razor v2 web site.
2. Copy and paste the following code into one of the content pages:

@{
//Check there are slider image page loaded
var theCount = @Model.Descendants("SliderImagePage").Count();
if (theCount > 0)
{
foreach (var theImagePage in Model.Descendants("SliderImagePage"))
{
var theImage = theImagePage.Media("sliderImage","umbracoFile");
if (theImagePage.IsFirst())
{
@:<div class="slide" style="background-image:url('@Html.Raw(theImage)');display:block;"></div>
} else {
@:<div class="slide" style="background-image:url('@Html.Raw(theImage)');display:none;"></div>
}
}
}
else
{
@: No Picture Image pages set up
}
}

(Note: The above code compiles without error in Razor v1.)
3. Attempt to build the site.

Result: The site will fail to compile with multiple errors. Scrutinizing the errors , reporting that the @: expression on line 11 requires a keyword, identifier, or string, and that the subsequent '}' character on line 12 closes the code block that began on line 1. If a user removes the "@" character on line 3 of the code snippet, the compilation proceeds without error.
Expected: The code snippet above should compile as it would have in Razor v1.
Comments: The at the beginning was not ever valid, it just slipped through validation in V1.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>