Skip to content

Documentation doesn't speak of required properties for Blazor parameters #47824

@NielsHoogeveen

Description

@NielsHoogeveen

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

When passing an instance of a reference type to a parameter in a blazor component, I can use someling like this:

[Parameter]
[EditorRequired]
public Model Model {get; set;}

This results in a warning that the property Model may be null.

Making the property required makes the warning go away. (Making it "init" prevents my code from accidentally updating the property).

[Parameter]
[EditorRequired]
public required Model Model {get; init;}

This seems to work and does everything I want. As far as I can tell, this behavior is not publically documenten, so I am not certain it will keep working in future versions of Blazor.

Describe the solution you'd like

Provide information in the documentation about the use of required and init for parameter and inject properties.

Additional context

No response

Metadata

Metadata

Assignees

Labels

✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor Components

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions