这是我的枚举:
public enum ValidityTypes : int
{
[Description("Not Set")]
None = 0,
[Description("Zero Validity")]
ZeroValidity = 1,
[Description("Life Time Validity")]
LifeTimeValidity = 2,
[Description("N Months")]
NMonths = 3,
[Description("Rehire Validity in Months")]
RehireValidity = 4
}
这里我设置了 Model 属性:
public ValidityTypes ValidityType { get; set; }
这是我的观点:
<label><b>Zero Validity:</b></label>
@if (Model.ValidityType == Constant.ValidityTypes.ZeroValidity)
{
@Html.RadioButtonFor(x => x.ValidityType, "1", new { @id = "validity1", style = "width:50px", @checked = "true" , onClick = "ValidityEnableDisable(this);" })
}
else
{
@Html.RadioButtonFor(x => x.ValidityType, "1", new { @id = "validity1", style = "width:50px", @checked = "false" , onClick = "ValidityEnableDisable(this);" })
}
<label><b>Life Time Validity: </b></label>
@if (Model.ValidityType == OneC.BGV.BE.Constant.ValidityTypes.LifeTimeValidity)
{
@Html.RadioButtonFor(x => x.ValidityType, "2", new { @id = "validity2", style = "width:50px", @checked = "true" , onClick = "ValidityEnableDisable(this);" })
}
else
{
@Html.RadioButtonFor(x => x.ValidityType, "2", new { @id = "validity2", style = "width:50px", @checked = "false" , onClick = "ValidityEnableDisable(this);" })
}
<label><b>'N' Months:</label>
@if (Model.ValidityType == OneC.BGV.BE.Constant.ValidityTypes.NMonths)
{
@Html.RadioButtonFor(x => x.ValidityType, "3", new { @id = "validity3", style = "width:50px", @checked = "true", onClick = "Validity3EnableDisable(this);" , autocomplete="off" })
@Html.TextBoxFor(x => x.ValidityValue, new { id = "NmonthTextbox", style = "width:50px" })
}
else
{
@Html.RadioButtonFor(x => x.ValidityType, "3", new { @id = "validity3", style = "width:50px", @checked = "false" , onClick = "Validity3EnableDisable(this);" , autocomplete="off"})
@Html.TextBoxFor(x => x.ValidityValue, new { id = "NmonthTextbox", style = "width:50px", disabled = "true" })
}
现在,当我加载此视图时,我得到model.Validitytype
的ZeroValidity
结果与数据库中的相同并满足第一个if
条件。但是在完整视图加载时,N months
单选按钮即将被选中。
为什么我无法显示选择的正确单选按钮?是不是我@checked
的控件属性不起作用?