Skip to content

Instantly share code, notes, and snippets.

@SQL-MisterMagoo
Last active October 28, 2024 07:08
Show Gist options
  • Select an option

  • Save SQL-MisterMagoo/bc5713fb26bf84bf810d48d1f45c361a to your computer and use it in GitHub Desktop.

Select an option

Save SQL-MisterMagoo/bc5713fb26bf84bf810d48d1f45c361a to your computer and use it in GitHub Desktop.
@foreach (var item in new string[] { "AspNetCore","AspNet","SomeJsThingWhatever"})
{
<div>
<input type="radio" name="technology" id="@item" value="@item" @onchange="RadioSelection" checked=@(RadioValue.Equals(item,StringComparison.OrdinalIgnoreCase)) />
<label for="@item">@item</label>
</div>
}
<div>
<label>Selected Value is @RadioValue</label>
</div>
@code
{
string RadioValue = "aspnetcore";
void RadioSelection(ChangeEventArgs args)
{
RadioValue = args.Value.ToString();
}
}
@dodyg

dodyg commented Aug 16, 2020

Copy link
Copy Markdown

The latest version of VS Preview doesn't run .NET 5.0 RC nightly build properly unfortunately :(

@SQL-MisterMagoo

Copy link
Copy Markdown
Author

Not sure what that had to do with this sample, which will work on the current official release?

@dodyg

dodyg commented Aug 16, 2020

Copy link
Copy Markdown

Oh ok. I didn't realize Preview 7 (current release) has support InputRadio. Because according to this tweet it's only available on Preview 8.

@SQL-MisterMagoo

Copy link
Copy Markdown
Author

It doesn't, this sample shows how to use native html radio inputs

@dodyg

dodyg commented Aug 16, 2020

Copy link
Copy Markdown

ah got it. Thanks.

@coultonluke

Copy link
Copy Markdown

Beautiful thanks. I don't know why the documentation doesn't work for this but this saved me time thanks!

@cfob

cfob commented Jan 31, 2021

Copy link
Copy Markdown

Only working example I have found. Many thanks.

@0ptim

0ptim commented Jul 30, 2021

Copy link
Copy Markdown

Thanks a lot! 💯

@chrisdeveloperit

Copy link
Copy Markdown

Thank you for this! Wish I found it days ago. It should be in the Blazor documentation.

@DesenEnterprises

Copy link
Copy Markdown

This is awesome, thank you so much! Life saver...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment