Skip to content

Component Parameters

Parameters allow components to accept input from their parent components, making them more flexible and reusable.

Basic Parameters

razor
@* GreetingComponent.razor *@
<div class="greeting">
    <h3>Hello, @Name!</h3>
</div>

@code {
    [Parameter]
    public string Name { get; set; }
}

Parameter Types

Simple Parameters

razor
[Parameter]
public string Title { get; set; }

[Parameter]
public int Count { get; set; }

[Parameter]
public bool IsActive { get; set; }

Complex Parameters

razor
[Parameter]
public Person User { get; set; }

[Parameter]
public List<string> Items { get; set; }

[Parameter]
public Dictionary<string, object> Properties { get; set; }

Expression Parameters

razor
[Parameter]
public Expression<Func<TItem, bool>> Condition { get; set; }

Parameter Attributes

Required Parameters

razor
[Parameter]
[EditorRequired]
public string RequiredValue { get; set; }

Cascading Parameters

razor
[CascadingParameter]
public Theme CurrentTheme { get; set; }