0

我有一个 C# MVC3 项目并且在实现 HTML.CheckBoxFor 时遇到了麻烦。我收到以下错误

Cannot implicitly convert type 'string' to 'bool'

这是代码:

@{ 

List<Domain.LookupCostReductions> costReductions = ViewBag.CostReductions;
    foreach (Domain.LookupCostReductions cr in costReductions)
    { 
        @: <td style="border:0 ;vertical-align: top; ">  
        @Html.CheckBoxFor(x => x.CostReduction, cr.Description) 
        @cr.Description 
        @:</td> 
    } 
}

有任何想法吗?

4

2 回答 2

2

我建议您的视图模型具有 CostReduction 属性的布尔数据类型,而不是在视图上进行转换。

于 2011-10-28T15:32:41.410 回答
1

x.CostReductionField 应该是 bool 类型。

尝试这个

  @Html.CheckBoxFor(x => Convert.ToBoolean(x.CostReduction), cr.Description)
于 2011-10-28T15:27:25.323 回答