radio buttons - how set with numeric value?

Posted 3 years ago by Rexadecimal
0

do radio buttons actually work in Blazor? Can I set an integer value to a radio button and bind it to an integer field? are there any code examples out there that work?

  • 0

    Here's a basic example that shows the radio buttons working

    <EditForm Model="radioModel" OnValidSubmit="HandleValidSubmit">
        <InputRadioGroup Name="radioGroup" @bind-Value="radioModel.RadioValue">
            <InputRadio Value="0" />First Radio<br />
            <InputRadio Value="1" />Second Radio<br />
        </InputRadioGroup>
        <button>Submit</button>
    </EditForm>
    
    <span>Selected Value:</span> @selectedVal
    
    @code {
        RadioModel radioModel = new RadioModel();
        int selectedVal;
    
        void HandleValidSubmit()
        {
            selectedVal = radioModel.RadioValue;
        }
    
        public class RadioModel
        {
            public int RadioValue { get; set; }
        }
    }
    Posted 3 years ago by selliott
Someone is typing...

Post a Reply

You must be logged in to add a new post.
Number of online users: 1
An error has occurred. This application may no longer respond until reloaded. Reload 🗙