Search code examples
asp.net-mvc-3checkboxfor

MVC3 HTML.CheckBoxFor error


I have a C# MVC3 project and am having trouble implementing the HTML.CheckBoxFor. I am getting the below error

Cannot implicitly convert type 'string' to 'bool'

Here's the code:

@{ 

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> 
    } 
}

Any ideas?


Solution

  • Rather than convert on the view, I would recommend your view model have the boolean data type for the CostReduction property.