ASP.NET布尔单选按钮显示为未选中

时间:2018-07-16 20:44:39

标签: html asp.net asp.net-mvc razor radio-button

我有以下两个带有“是”和“否”标签的单选按钮,它们映射到布尔值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; }

当新用户提交表单并选择任意一个单选按钮时,truefalse值将正确设置为AgreeToTerms布尔值(我可以在我们的SQL数据库)。但是,当管理员查看用户提交的此表单时,将使用与上面相同的HTML代码向管理员显示该表单。管理员看到的屏幕截图如下:两个空白单选按钮:

enter image description here

这是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的真值或假值?

0 个答案:

没有答案