我刚刚开始发现FluentHml,我被CheckBoxList助手卡住了。
以下是代码
<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“开头,我想禁用复选框
我怎样才能做到这一点呢?
谢谢,哈桑
发布于 2010-08-05 23:04:59
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>
<%}%>https://stackoverflow.com/questions/3062398
复制相似问题