views:

44

answers:

1

Hi,

I have just started to discover FluentHml and I'm stuck with the CheckBoxList Helper.

Here is the code

<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>

So, I have a checkboxlist based on "criteria.Choices" which is typed as List<ChoiceViewModel>.

Here is the code of a ChoiceViewModel

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

And my problem is : I want to disable the checkbox under a condition.

Let's say that if the Code doesn't start with an "A", I want to disable the checkbox

How can I achieve that ?

Thanks, Hasan

A: 

CheckboxList does not provide that. You can do it with CheckBox in loop. Something like this:

<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>
<%}%>
Tim Scott