Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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})
like image 829
user603007 Avatar asked Dec 29 '25 03:12

user603007


1 Answers

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)
}
like image 180
Łukasz W. Avatar answered Dec 30 '25 18:12

Łukasz W.