我有以下两个带有“是”和“否”标签的单选按钮,它们映射到布尔值AgreeToTerms
。这是HTML表单:
<div class="control">
@Html.LabelFor(model => model.AgreeToTerms)<br />
@Html.RadioButtonFor(model => model.AgreeToTerms, true) Yes<br />
@Html.RadioButtonFor(model => model.AgreeToTerms, false) No
</div>
这是模型:
[Display(Name = "Do you agree to the terms?")]
public bool AgreeToTerms { get; set; }
当新用户提交表单并选择任意一个单选按钮时,true
或false
值将正确设置为AgreeToTerms
布尔值(我可以在我们的SQL数据库)。但是,当管理员查看用户提交的此表单时,将使用与上面相同的HTML代码向管理员显示该表单。管理员看到的屏幕截图如下:两个空白单选按钮:
这是AgreeToTerms
设置为false时生成的HTML:
<div class="control">
<label for="AgreeToTerms">Do you agree to the terms?</label><br />
<input data-val="true" field" id="AgreeToTerms" name="AgreeToTerms" type="radio" value="True" /> Yes<br />
<input checked="checked" id="AgreeToTerms" name="AgreeToTerms" type="radio" value="False" /> No
</div>
并且将AgreeToTerms
设置为true时:
<div class="control">
<label for="AgreeToTerms">Do you agree to the terms?</label><br />
<input checked="checked" data-val="true" id="AgreeToTerms" name="AgreeToTerms" type="radio" value="True" /> Yes<br />
<input id="AgreeToTerms" name="AgreeToTerms" type="radio" value="False" /> No
</div>
如何获取单选按钮以显示AgreeToTerms
的真值或假值?