Aspnetcore: .razor parsing forces code blocks, even in functions block

Created on 22 Apr 2019  路  7Comments  路  Source: dotnet/aspnetcore

Describe the bug

The compiler does not allow "single-statement control flow statements" In the "cshtml" part of a .razor file. I understand that is required, but currently it also enforces this rule in the "@functions" block. My understanding was that in the @functions block any normal c# syntax can be used.

To Reproduce

"dotnet new blazorserverside"
Edit the "components.razor" file and replace the "IncrementCount" function with:

 void IncrementCount()
    {
        if (true)
        currentCount++;
    }

Expected behavior

It should not give a compile time syntax error

Done area-blazor bug

All 7 comments

I would also like to support the code without using {}

We are able to reproduce this.

(This appears to be a regression in preview4 compared to preview3.)

Using VS 2019 16.1 Preview 2 with 3.0.0 Preview 4

I am facing the same issue using VS2019 16.1 Preview 2 and .NET Core 3.0.0-preview4.

https://gist.github.com/MaherJendoubi/d6e15a1da422dc33cb8b4d27916a5fe5

Razor engine cannot parse the lambda expression at line number 51:

receiveClient.RegisterMessageHandler(
async (message, cancellationToken) => await receiveClient.CompleteAsync(message.SystemProperties.LockToken),
messageHandlerOptions);

Still working on fixing this :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danroth27 picture danroth27  路  130Comments

danroth27 picture danroth27  路  79Comments

radenkozec picture radenkozec  路  114Comments

glennc picture glennc  路  117Comments

zorthgo picture zorthgo  路  136Comments