2011-10-28 46 views
0

我有一個C#MVC3項目,並且無法實現HTML.CheckBoxFor。我提示以下錯誤: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> 
    } 
} 

任何想法?

回答

2

而不是轉換上的觀點,我會建議您的視圖模型具有的CostReduction屬性的布爾數據類型。

+0

@Jared ...謝謝 – MikeTWebb

0

x.CostReductionField應該是bool類型。

試試這個

@Html.CheckBoxFor(x => Convert.ToBoolean(x.CostReduction), cr.Description)