Can I make component parameter required when building a custom Blazor component?

.NET 6 and newer

This can be accomplished with the [EditorRequired] attribute. Example:

[Parameter, EditorRequired]
public string Name { get; set; }

This will give an IDE warning to consumers of components that parameters are missing if their parameters are not supplied.

Before .NET 6

Currently, you’ll have to do exactly as you said.

Leave a Comment