0

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?

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

x.CostReductionField should be of type bool.

Try this

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.