我的 Html 代码如下。但始终将最终选项按钮选中为选中的。我该如何解决这个问题?
<div id="employee" style="margin: 7px 0;">
<div>
<input id="james-johnson" type="radio" name="employee" value="james-johnson" checked="checked"><label for="james-johnson">James Johnson</label>
</div>
<div>
<input id="boss-hog" type="radio" name="employee" value="boss-hog" checked="unchecked"><label for="boss-hog">Boss Hog</label>
</div>
<div>
<input id="jake-sanders" type="radio" name="employee" value="jake-sanders" checked="unchecked"><label for="jake-sanders">Jake Sanders</label>
</div>
<div>
<input id="dawn" type="radio" name="employee" value="dawn" checked="unchecked"><label for="dawn">Dawn</label>
</div>
</div>
ASPX 代码如下
<div id="employee" style="margin: 7px 0;">
<% foreach (var employee in Model.Provider.Employees)
{ %><div>
<input id="<%: employee.Key %>"
type="radio" name="employee" value="<%: employee.Key %>" checked="<%:employee.IsEmployeeSelected ?? "unchecked" %>" /><label for="<%: employee.Key %>"><%: employee.Name%></label>
</div>
<% } %>
</div>
更新(当我应用 @Satpal 方法时):
<div id="employee" style="margin: 7px 0;">
<div>
<input id="james-johnson" type="radio" name="employee" value="james-johnson" checked="checked"><label for="james-johnson">James Johnson</label>
</div>
<div>
<input id="boss-hog" type="radio" name="employee" value="boss-hog" checked=""><label for="boss-hog">Boss Hog</label>
</div>
<div>
<input id="jake-sanders" type="radio" name="employee" value="jake-sanders" checked=""><label for="jake-sanders">Jake Sanders</label>
</div>
<div>
<input id="dawn" type="radio" name="employee" value="dawn" checked=""><label for="dawn">Dawn</label>
</div>
</div>