0

我有一个下拉列表和一个日期字段。如果从下拉列表中选择了一个特定值,则日期字段应该是必需的。为了解决这个问题,我尝试使用 FoolProof 库中的 requiredIf 属性。

但我不知道如何访问模型中的选定值。

模型

//This is the datefield
[RequiredIf(tabState == "discarded")]
[DataType(DataType.Date)]
[Display(Name = "date discarded")]
public Nullable<System.DateTime> datDiscarded { get; set; }

//This is the dropdown
public virtual tabState tabState { get; set; }

控制器中的选项卡状态

ViewBag.intIdeaStateID = new SelectList(db.tabState, "intStateID", "strState");

视图中的下拉菜单

<div class="form-group">
    @Html.LabelFor(model => model.intIdeaStateID, "State", htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.DropDownList("intIdeaStateID", null, htmlAttributes: new { @class = "form-control" })
        @Html.ValidationMessageFor(model => model.intIdeaStateID, "", new { @class = "text-danger" })
    </div>
</div>

如何检查下拉列表中选择的值是否“丢弃”?

谢谢你的帮助。

4

0 回答 0