I need to show different components based on a radio selection so I'm using InputRadioGroup like described here.
When either of the options is selected, the page rerenders, the correct component is shown, but the InputRadioGroup is rerendered again and not preserving the selection. I've tried to put InputRadioGroup in a <EditForm Model="ColorInt" but the same thing happens. I've even tried the checked="@(ColorInt == 1)" approach, but it's not working either. This was a reported bug which have been solved in .NET 7, but it still happens to me.
<InputRadioGroup Name="color" @bind-Value="ColorInt"> Colors:<div style="margin-bottom:5px"><div><label><InputRadio Name="color" Value="1" checked="@(ColorInt == 1)" /> Red</label></div><div><label><InputRadio Name="color" Value="2" checked="@(ColorInt == 2)" /> Green</label></div><div><label><InputRadio Name="color" Value="3" checked="@(ColorInt == 3)" /> Blue</label></div></div></InputRadioGroup>@switch (ColorInt){ case 1: { <red /> break; } case 2: { <green/> break; } case 3: { <blue/> break; } }@code { private int ColorInt{ get; set; } = 1;}P.S. Just stupid from me...because of need of editing my actual code I've never checked this. My Value actually comes from a static class MagicStrings that holds some const values for my entire app.
<InputRadio Name="color" Value="@MagicStrings.RedColor" />Now MagicStrings.RedColor type was byte
public const byte RedColor = 1;@code { private int ColorInt{ get; set; } = @MagicStrings.RedColor; // which was byte}