値が何であるかに関係なく、disabled属性がCheckBoxを無効にするため、機能していません。
これを1行で行う方法はわかりませんが、次の1つの解決策があります。
@if(Model.Disabled)
{
@Html.CheckBoxFor(m=>m.Checked, new { @disabled = "disabled"})
}
else
{
@Html.CheckBoxFor(m=>m.Checked)
}
潜在的なHTMLヘルパー拡張機能:
public static MvcHtmlString CheckBoxFor<TModel>(
this HtmlHelper<TModel> helper,
Expression<Func<TModel, bool>> expression,
object htmlAttributes,
bool isDisabled)
{
var dic = htmlAttributes.GetType()
.GetProperties()
.ToDictionary(p => p.Name, p => p.GetValue(htmlAttributes, null));
if (isDisabled)
dic["disabled"] = "disabled";
return helper.CheckBoxFor(expression, dic);
}