question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.razor parsing forces code blocks, even in functions block

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

Multiple code blocks in Razor and Parser Error
I have an issue in my MVC site. I have a using and a fieldlist in that, and in that a code block....
Read more >
Ten Tricks for Razor Views
1. Code Blocks and Variables. In Razor you can create blocks of code nearly anywhere using @{ }. A block of code doesn't...
Read more >
Razor syntax reference for ASP.NET Core
Razor is a markup syntax for embedding .NET based code into webpages. The Razor syntax consists of Razor markup, C#, and HTML. Files...
Read more >
Help me understand AutoCompletion and .. ...
The project I am working on is currently small, only about 20 files total, but includes many wxWidgets widgets. It still cannot parse...
Read more >
ScottGu's Blog - ASP.NET MVC 3: Razor's @: and <text> syntax
One of the techniques that Razor uses to implicitly identify when a code block ends is to look for tag/element content to denote...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found