How can I dynamically render components using MudBlazor radio buttons?

MudBlazorLogo

You need to have a MudRadioGroup to contain your MudRadio buttons. On the MudRadioGroup you have the @bind-SelectedOption event callback exposed. You can set a switch statement on that to dynamically render your other components.

Parent Component:

<MudForm>
    <MudRadioGroup @bind-SelectedOption="@SelectedOption">
        <MudRadio Option="@("Add")" Color="Color.Primary">Primary</MudRadio>
    </MudRadioGroup>
</MudForm>

@switch(SelectedOption)
{
    case "Add":
        <TestComponent />
    break;
}

<div class="d-flex align-center">
    <MudButton Variant="Variant.Outlined" OnClick="Reset">Reset</MudButton>
    <MudText Class="ml-4">Selected Option: @SelectedOption</MudText>
</div>

@code {
    public string SelectedOption { get; set; }

    private void Reset()
    {
        SelectedOption = null;
    }
}

TestComponent.razor

<h1>Hi from: TestComponent</h1>

Sample Project

https://try.mudblazor.com/snippet/wOmRucPSpMDbtnAw

Need a hand with your Blazor or .NET project?

Get in touch
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.