I wanted to make a radio button list which is bound to a model in asp.net core. But, I also wanted the unique labels to be clickable and associated with each radio button. I have this:
<fieldset>
<div>
<span>
<input type="radio" required asp-for="Email" value="EmailYes" /> <b>Send Email:</b> They will be sent an email.
</span>
</div>
<div>
<span>
<input type="radio" required asp-for="Email" value="EmailNo" /> <b>Do Not Send Email:</b> They will not be sent an email.
</span>
</div>
</fieldset>
I've tried adding a label like so:
<label asp-for="EmailYes"><b>Send Email:</b> They will be sent an email. </label>
But when the user clicks on the second label, it selects the first radio button.
Thanks.
Got it:
<fieldset>
<div>
<span>
<input type="radio" required asp-for="Email" id="EmailYes" value="EmailYes" />
<label for="EmailYes"><b>Send Email:</b> They will be sent an email. /label>
</span>
</div>
<div>
<span>
<input type="radio" required asp-for="Email" id="EmailNo" value="EmailNo" />
<label for="EmailYes"><b>Do Not Send Email:</b> They will not be sent an email. /label>
</span>
</div>
I was hoping to use only .Net Core tag helpers. But this works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With