dark_ruby
dark_ruby

Reputation: 7866

Understanding Blazor props syntax

I know C# but been mostly programming React lately, I'm now looking at Blazor and trying to understand its quirky syntax.

I'm seeing in different examples that when passing props (attributes) to components an @ sign is being used in various locations:

examples I've seen:

What are these? I noticed that having no @ often works the same as with it. Official documentation doesn't go to depth re this

Upvotes: 2

Views: 1408

Answers (1)

Henk Holterman
Henk Holterman

Reputation: 273179

I'm seeing in different examples that when passing props (attributes) to components an @ sign is being used in various locations

Yes, this has changed a few times over the preview releases. As a consequence, some blogs and samples will be out of date. So first thing to check: how old is this code or article?

The official docs don't talk about those changes but they are up to date with the latest version.

The main changes were in preview6 : "In this Blazor release we’ve standardized on a common syntax for directive attributes."

My simple summary: Blazor attributes (directives) start with @, normal HTML attributes do not.
The values of those attributes (binding or eventhandler) do not need a @

In a later preview it was determined that attibutes should be case-sensitive.

Upvotes: 3

Related Questions