禁用 MVcContrib.FluentHtml.CheckboxList 中的复选框

发布于 2024-09-06 12:33:59 字数 830 浏览 17 评论 0原文

我刚刚开始发现 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”开头,我想禁用该复选框

如何实现?

谢谢, 哈桑

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

也只是曾经 2024-09-13 12:33: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>
<%}%>

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>
<%}%>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文