【问题标题】:Disable a checkbox in a MVcContrib.FluentHtml.CheckboxList禁用 MVcContrib.FluentHtml.CheckboxList 中的复选框
【发布时间】:2010-06-17 14:13:43
【问题描述】:

我刚刚开始发现 FluentHml,我被 CheckBoxList Helper 卡住了。

这里是代码

<ul>
      <%=this.CheckBoxList(m=>m.Filter)
                .Options(criteria.Choices, x => x.Code, x => x.DisplayText)
                .Selected(Model.Filter)
                .Label(criteria.Label).ItemFormat("<li> {0} </li>")

      %>
</ul>

所以,我有一个基于“criteria.Choices”的复选框列表,其类型为 List

这是 ChoiceViewModel 的代码

public class ChoiceViewModel
{
    // Some stuff
    public string Code { get{ return _code; } }
    public string Label { get { return _label; }}
    public string DisplayText { get { return _displayText;}
    }
}

我的问题是: 我想在某个条件下禁用复选框。

假设代码不以“A”开头,我想禁用复选框

我怎样才能做到这一点?

谢谢, 哈桑

【问题讨论】:

    标签: mvccontrib fluenthtml


    【解决方案1】:

    CheckboxList 不提供。您可以在循环中使用 CheckBox 来完成。像这样的:

    <label>criteria.Label</label> 
    <%foreach (var choice in criteria.Choices) {%>
       <li>
          <%=this.CheckBox(m => m.Filter)
             .Value(choice.Code)
             .Checked(choice == Model.Filter)
             .Label(choice.Code.DisplayText)
             .Disabled(choice.Code.StartsWith("A")%>
       </li>
    <%}%>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-22
      相关资源
      最近更新 更多