I’m trying to create a dynamic CheckBoxFor where some items are disabled.
This is disabling everything:
@Html.CheckBoxFor(m=>m.Checked, new { @disabled = "disabled"})
I was trying to create something like this without success:
@Html.CheckBoxFor(m=>m.Checked, new{ @disabled = @(Model.Disable ? "disabled" : "")})
One note, my Model has a property called Disabled and another Checked.
It’s not working because the disabled attribute disables a CheckBox regardless of what it’s value is.
I’m not sure how to do this in one line, but here’s one solution:
A potential Html Helper Extension: