Moved from MVC, original issue: aspnet/Mvc#2843 by @lenardg
In the following situation the error message that Razor gives me is very misleading.
I have the following code in a .CSHTML file:
@if (Model.Results.Any()) {
@foreach (var result in Model.Results) {
// some HTML code and Razor values
<div>
@result.SomeValue.
</div>
// some more HTML code
}
}
Which results in an error message as follows:
An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.
And also:
Identifier expected
The identifier expected references the line @result.SomeValue. in it. This line is included in the example above.
The error goes away if I remove the @ mark before @foreach, and just specify foreach
The error is caused by having a . (dot character) after SomeValue. I can either make this work by removing the dot or by remove the @ mark before @foreach. Note the dot character is indeed required, because we want to show the value followed by a dot.
Just to summarize, I am not objecting to how Razor works, but how this error is presented. It took some time to realize what I needed to do. Also, Visual Studio gave no indication something was wrong (VS2015 RTM)