隐藏div取决于列值

时间:2019-02-04 14:09:19

标签: asp.net-mvc

如果大学录取=“ C”或“ U”,我需要隐藏“ Firm” div组。大学录取还可以是“ R”(已拒绝)和“ P”(待定)。

'

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

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

'

1 个答案:

答案 0 :(得分:0)

尝试如下:

@{
   if(!(Model.UniversityOffer == "C" || Model.UniversityOffer == "U"))
   {
      <div class="form-group">
            @Html.LabelFor(model => model.Firm, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <div class="checkbox">
                    @Html.EditorFor(model => model.Firm)
                    @Html.ValidationMessageFor(model => model.Firm, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>
   }

}