This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
Exception filters cause Razor errors #402
Closed
Description
If you write:
@try
{
throw new InvalidOperationException();
}
catch (Exception e) when (e.Message.Contains("Operation is not valid"))
{
}
You get the following error:
CompilationFailedException: Compilation for 'c:\......\Index.cshtml' failed:
Expected a "{" but found a "if". Block statements must be enclosed in "{" and "}". You cannot use single-statement control-flow statements in CSHTML pages. For example, the following is not allowed:
@if(isLoggedIn)
<p>Hello, @user</p>
Instead, wrap the contents of the block in "{}":
@if(isLoggedIn) {
<p>Hello, @user</p>
}