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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.