默认情况下,可空标识符使单选按钮列表在第一页加载时不检查任何单选按钮。这是处理这种情况的正确方法吗?或者什么是最佳实践?
模型:
[Required]
public SomeEnum? Choices { get; set; }
public enum SomeEnum
{
OptionOne,
OptionTwo
}
看法:
<div>
@Html.ValidationMessageFor(x => x.Choices)
@Html.RadioButtonFor(x => x.Choices, SomeEnum.OptionOne)
@Html.RadioButtonFor(x => x.Choices, SomeEnum.OptionTwo)
</div>
呈现的 HTML:
<div>
<input name="Choices" id="Choices" type="radio" data-val-required="The Choices field is required." data-val="true" value="OptionOne"></input>
<input name="Choices" id="Choices" type="radio" value="OptionTwo"></input>
</div>