.NET core asp-for 单选按钮绑定到具有可点击标签的模型?

Chr*_*s J 6 .net html asp.net label

我想制作一个绑定到 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>
Run Code Online (Sandbox Code Playgroud)

我尝试添加一个标签,如下所示:

  <label asp-for="EmailYes"><b>Send Email:</b> They will be sent an email. </label>
Run Code Online (Sandbox Code Playgroud)

但是当用户单击第二个标签时,它会选择第一个单选按钮。

谢谢。

Chr*_*s J 5

知道了:

<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>
Run Code Online (Sandbox Code Playgroud)

我希望仅使用 .NET Core 标记帮助程序,但这可行。