My ViewModel has a property of selected and selectable. Both are boolean. I would like my view to have a checkbox that is enabled when selectable is true and disabled when
Sorry, my previous answer was wrong.
The input-element will be disabled as soon as it gets the attribute disabled. It doesn't matter if the value is true, false. In HTML you can't set disabled to false.
So you will have to set the disabled attribute only when the condition is valid.
something like:
object attributes = null;
if (!item.Selectable)
{
attributes = new { disabled = "disabled"};
}
@Html.CheckBoxFor(modelItem => item.Selected, attributes)