Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I mix C# and JS inside a Razor partial view (see repro below, it pretty much shows the issue in a single glance): I use the < character for a "less than" comparison in JS, but this seems to confuse the Razor compiler as it thinks this is the start of an HTML tag. The error message is
error RZ1024: End of file or an unexpected character was reached before the "" tag could be parsed. Elements inside markup blocks must be complete. They must either be self-closing ("<br />") or have matching end tags ("<p>Hello</p>"). If you intended to display a "<" character, use the "<" HTML entity.
Expected Behavior
The Razor view compiles without error, as the code is correct and valid.
Steps To Reproduce
Create a partial view in an ASP.NET 6 MVC project, with this content (minimal repro)
<script>
function myFunction() {
@if (true)
{
<text>
// the following line throws the compile error, as the compiler seems to think that the "less than" character is the start of an HTML tag, not JS
var a = 1 < 1;
</text>
}
}
</script>
and try to compile the project -> the line var a = 1 < 1
will throw the above compilation error.
Exceptions (if any)
No response
.NET Version
6.0.300
Anything else?
Runtime Environment:
OS Name: Mac OS X
OS Version: 12.5
OS Platform: Darwin
RID: osx.12-arm64
We found this issue when migrating a very old .NET Core 2.2 application to .NET 6.0. It seems that the error does not occur in .NET Core 2.2 on Windows, so it may either be an issue on MacOS or with the newer .NET version.
Activity