Asp.net mvc 显示“是”和“否”复选框

Asp.net mvc 显示“是”和“否”复选框,asp.net-mvc,Asp.net Mvc,我在数据库中有一个名为PermanentAddressChk的字段,保存为bit 我需要为PermanentAddressChk字段显示两个复选框“是”和“否” 下面的代码工作正常,但是有更好的方法吗?欢迎新想法,干杯 <br />@Html.Label("Yes") @Html.CheckBoxFor(m => m.PermanentAddressChk, htmlAttributes: new { @checked = true }) <br />&nb

我在数据库中有一个名为PermanentAddressChk的字段,保存为bit

我需要为PermanentAddressChk字段显示两个复选框“是”和“否”

下面的代码工作正常,但是有更好的方法吗?欢迎新想法,干杯

<br />@Html.Label("Yes")
@Html.CheckBoxFor(m => m.PermanentAddressChk, htmlAttributes: new { @checked = true })
<br />&nbsp @Html.Label("No")
@Html.CheckBoxFor(m => m.PermanentAddressChk, htmlAttributes: new { @checked = false})

@Html.Label(“是”) @CheckBoxFor(m=>m.PermanentAddressChk,htmlAttributes:new{@checked=true})
@Html.Label(“否”) @CheckBoxFor(m=>m.PermanentAddressChk,htmlAttributes:new{@checked=false})
我知道你说你在寻找两个复选框,但这里有一个例子,是/否单选按钮,以防感兴趣

<div id="radioButtonDiv" >
    @Html.LabelFor(model => model.PermanentAddressChk, "Is address permanent?")
    <div>
        @Html.RadioButtonFor(model => model.PermanentAddressChk, true, new { id = "isPermanentAddressTrue" }) @Html.Label("isPermanentAddressTrue", "Yes")
        @Html.RadioButtonFor(model => model.PermanentAddressChk, false, new { id = "isPermanentAddressFalse" }) @Html.Label("isPermanentAddressFalse", "No")
    </div>
</div>

@LabelFor(model=>model.PermanentAddressChk,“地址是永久的吗?”)
@Html.radiobutton(model=>model.PermanentAddressChk,true,new{id=“isPermanentAddressTrue”})@Html.Label(“isPermanentAddressTrue”,“Yes”)
@Html.radiobutton(model=>model.PermanentAddressChk,false,new{id=“isPermanentAddressFalse”})@Html.Label(“isPermanentAddressFalse”,“No”)

这允许您使用single PermanentAddressChk属性从控制器引用bool值,以及通过javascript引用单个单选按钮值。这也会在单选按钮选项旁边显示“是/否”

我知道你说你在寻找两个复选框,但这里有一个例子,是/否单选按钮,以防感兴趣

<div id="radioButtonDiv" >
    @Html.LabelFor(model => model.PermanentAddressChk, "Is address permanent?")
    <div>
        @Html.RadioButtonFor(model => model.PermanentAddressChk, true, new { id = "isPermanentAddressTrue" }) @Html.Label("isPermanentAddressTrue", "Yes")
        @Html.RadioButtonFor(model => model.PermanentAddressChk, false, new { id = "isPermanentAddressFalse" }) @Html.Label("isPermanentAddressFalse", "No")
    </div>
</div>

@LabelFor(model=>model.PermanentAddressChk,“地址是永久的吗?”)
@Html.radiobutton(model=>model.PermanentAddressChk,true,new{id=“isPermanentAddressTrue”})@Html.Label(“isPermanentAddressTrue”,“Yes”)
@Html.radiobutton(model=>model.PermanentAddressChk,false,new{id=“isPermanentAddressFalse”})@Html.Label(“isPermanentAddressFalse”,“No”)

这允许您使用single PermanentAddressChk属性从控制器引用bool值,以及通过javascript引用单个单选按钮值。这也会在单选按钮选项旁边显示“是/否”

您可以这样做:

View=>您只需要一个复选框,因为如果不选中,您将在控制器中收到false

<div class="form-group">
    @Html.LabelFor(m => m.PermanentAddressChk, new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.EditorFor(m => m.PermanentAddressChk)
        @Html.ValidationMessageFor(m => m.Active)
    </div>
</div>
Css=>

.form-group {
  margin-bottom: 15px;
}
.control-label {
 padding-top: 7px;
 margin-bottom: 0;
 text-align: right;
 margin-bottom: 0;
 vertical-align: middle;
}

你可以这样做:

View=>您只需要一个复选框,因为如果不选中,您将在控制器中收到false

<div class="form-group">
    @Html.LabelFor(m => m.PermanentAddressChk, new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.EditorFor(m => m.PermanentAddressChk)
        @Html.ValidationMessageFor(m => m.Active)
    </div>
</div>
Css=>

.form-group {
  margin-bottom: 15px;
}
.control-label {
 padding-top: 7px;
 margin-bottom: 0;
 text-align: right;
 margin-bottom: 0;
 vertical-align: middle;
}

那么它们都可以检查?单选按钮用于多个选项,其中只能选择一个选项。因此,它们都可以选中?单选按钮用于多个选项,其中只能选择一个选项。非常感谢各位。非常感谢各位。