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
It is not easy to achieve this with an if
condition inside the helper method because all the below markups will render a disabled chechbox.
This should work in the razor. Simple If condition and rendering what you want.
@if(item.Selected)
{
@Html.CheckBoxFor(modelItem => item.Selected)
}
else
{
@Html.CheckBoxFor(modelItem => item.Selected, new { @disabled = "disabled"})
}
You may consider writing a custom html helper which renders the proper markup for this.