Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am getting an error like this '
Error CS0029 Cannot implicitly convert type 'string' to 'bool' '

and another error
'
Error CS1662 Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type '

Please Help me to solve this error.

What I have tried:

<div class="col-md-10">
                  @*@Html.EditorFor(model => model.hobbies, new { htmlAttributes = new { @class = "form-control" } })*@
                  @Html.LabelFor(model => model.hobbies, "Cricket")
                  @Html.CheckBoxFor( model=>model.hobbies,"Cricket")
                  @Html.LabelFor(model => model.hobbies, "Singing")
                  @Html.CheckBoxFor(model => model.hobbies, "Singing")
                  @Html.LabelFor(model => model.hobbies, "Reading")
                  @Html.CheckBoxFor(model => model.hobbies, "Reading")
                  @Html.LabelFor(model => model.hobbies, "Dancing")
                  @Html.CheckBoxFor(model => model.hobbies, "Dancing")

                  @Html.ValidationMessageFor(model => model.hobbies, "", new { @class = "text-danger" })
              </div>
Posted
Updated 12-Jan-22 16:40pm
v2
Comments
Richard Deeming 29-Nov-21 4:21am    
We can't see your model. At a guess, the hobbies property is not a bool, and therefore cannot be used with CheckBoxFor.
j snooze 30-Nov-21 17:26pm    
Maybe check out this post on how to make a checklistbox in MVC
https://stackoverflow.com/questions/37778489/how-to-make-check-box-list-in-asp-net-mvc

1 solution

It must be because of your model is String not Boolean. Just check your "Hobbies" datatype in Model. If it's string, then you must change it into Boolean. Because razor CheckBoxFor is only accept Boolean datatype.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900