1

'Supplier' 表中的每条记录都有一个 bool 'SupplierEmailProvided' 列。要在屏幕上显示值:

@Model.Suppliers.Where(s => s.Id == products.PreferredSupplierId).FirstOrDefault().SupplierEmailProvided

这很好用,但是 ATM 会根据其值显示“真”或“假”(在屏幕上)。

我想将其更改为一个复选框,如果值为 FALSE,则禁用该复选框

尝试过类似的东西:@Html.CheckBoxFor(s => s.Suppliers.Where(x => x.SupplierEmailProvided)).FirstOrDefault().SupplierEmailProvided'

但不好。有什么想法吗?

编辑 所以我之前已经给出了所有建议。

@if((s => s.Id == products.PreferredSupplierId).FirstOrDefault().SupplierEmailProvided)
                     {   
                            @Html.CheckBoxFor(s => s.Suppliers
                                                    .Where(x => x.Id == products.PreferredSupplierId)
                                                    .FirstOrDefault()
                                                    .SupplierEmailProvided)

                             @Html.CheckBox("SupplierEmailProvided",true,
                             (Model.Suppliers.Where(x => x.SupplierEmailProvided)).FirstOrDefault().SupplierEmailProvided 
                             ? (object) new { disabled = "false" } : (object) new {disabled = "true" })
                     }

如果语句说“操作员”,则开头。不能应用于 lamba 类型的 opperad 吗?

有什么帮助吗?

4

3 回答 3

2

假设SupplierEmailProvided是布尔类型,虽然逻辑应该很清楚,但尚未测试

正如您所提到的,当值为 false 时,复选框应处于禁用状态。

@if(Model.Suppliers.Where(x => x.SupplierEmailProvided)).FirstOrDefault().SupplierEmailProvided)
{
     Html.CheckBox("SupplierEmailProvided",true)
}else
{
     Html.CheckBox("SupplierEmailProvided",false,new{ disabled ="true"} )
}
于 2013-07-17T13:32:36.837 回答
0

你试过这个吗?

@if(Model.Suppliers.FirstOrDefault(s => s.Id == products.PreferredSupplierId).SupplierEmailProvided)
{
    html code 
}
else 
{
    ...
}
于 2013-07-17T13:17:33.540 回答
0

应该工作,检查你的CheckBoxFor括号,也许将作业分成两半:

@{
    var supplier = Model.Suppliers.Where(s => s.Id == products.PreferredSupplierId).FirstOrDefault();
}
@Html.CheckBoxFor(model => supplier.SupplierEmailProvided)

或者在你做的一行中:

@Html.CheckBoxFor(model => model.Suppliers
                                .Where(s => s.Id == products.PreferredSupplierId)
                                .FirstOrDefault()
                                .SupplierEmailProvided)
于 2013-07-17T13:31:53.240 回答