user603007
user603007

Reputation: 11794

how to make @Html.CheckBoxFor invisible?

how do you make @Html.CheckBoxFor invisible with use of the htmlAttributes?

I tried:

   @Html.CheckBoxFor(modelItem => modelItem.DeleteEnabled, new {visible= @modelItem.Visible})

Upvotes: 3

Views: 4916

Answers (1)

Łukasz W.
Łukasz W.

Reputation: 9755

You can try like this:

@Html.CheckBoxFor(modelItem => modelItem.DeleteEnabled, 
                  new { style = modelItem.Visible ? 
                                    string.empty : 
                                    "display:none"})

or if you do not need it at the page source at all, nor even hidden then use @if for example:

@if(modelItem.Visible)
{
    @Html.CheckBoxFor(modelItem => modelItem.DeleteEnabled)
}

Upvotes: 2

Related Questions