3

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

I tried:

   @Html.CheckBoxFor(modelItem => modelItem.DeleteEnabled, new {visible= @modelItem.Visible})
1
  • 3
    hey there, can i ask you why you don't just use the Html.HiddenFor() helper instead?? to me it sounds like bad design to have a 'type' like a checkbox hidden, with no obvious explanation. i 'get' the requirement to have it disabled, but hidden is just weird :-) Commented Jul 30, 2012 at 12:32

1 Answer 1

2

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)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.