Access public virtual dropdown value

116 Views Asked by At

I have a dropdown list and a datefield. If there is one specific value selected from the dropdown, the datefield should be required. To solve that, I tried to use the requiredIf sttribute from the FoolProof library.

But I don't know how to access the selected value in the Model.

Model

//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; }

tabState in Controller

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

dropdown in View

<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>

How can I check if the selected value from the dropdown is "discarded"?

Thanks for your help.

0

There are 0 best solutions below