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 に答える