我想制作一个绑定到asp.net core中的模型的单选按钮列表。但是,我还希望独特的标签可单击并与每个单选按钮相关联。我有这个:
<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>
我尝试添加这样的标签:
<label asp-for="EmailYes"><b>Send Email:</b> They will be sent an email. </label>
但是当用户单击第二个标签时,它会选择第一个单选按钮。
谢谢。
明白了:
<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="EmailNo"><b>Do Not Send Email:</b> They will not be sent an email. /label>
</span>
</div>
我希望仅使用 .NET Core 标记帮助程序,但这可行。