I wan't to hide / show elements in .cshtml file based on the value of a boolean. With a form (setting.cshtml) I put the value of a boolean (true/false) and an ID in a MongoDB database.

In another form (RuleForm.cshtml) I want to use the value of that boolean. If the boolean is true, I wan't to display an input field, if the value is false, I don't want to display the input field.

This is one input field in RuleForm.cshtml:

<div class="editor-label">
  @Html.LabelFor(model => model.BedrijfsNummer)
</div>
<div class="editor-field">
  @Html.EditorFor(model => model.BedrijfsNummer)
  @Html.ValidationMessageFor(model => model.BedrijfsNummer)
</div>

But what I want is something like this:

@{if(bool(BooleanOne) = true) {
  <div class="editor-label">
    @Html.LabelFor(model => model.BedrijfsNummer)
  </div>
  <div class="editor-field">
    @Html.EditorFor(model => model.BedrijfsNummer)
    @Html.ValidationMessageFor(model => model.BedrijfsNummer)
  </div>
}

I think the problem is, is that I use two different models, one for Settings.cshtml and one for RuleForm.cshtml.

Related posts

Recent Viewed