Wednesday 13 July 2022

Fix Error CS0266 Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?)


Watch this example on YouTube:


 


to fix it replace

@model WebApplication3.Models.EmployeeList


@using (Html.BeginForm(null, null, FormMethod.Post))

{

    if (Model.myEmployees != null)

    {

        foreach (var item in Model.myEmployees)

        {

                        @Html.CheckBoxFor(modelItem => item.IsValid, new { id = item.EmployeeID })

                        @Html.DisplayFor(modelItem => item.FirstName)

        }

    }

}

with

@model WebApplication3.Models.EmployeeList


@using (Html.BeginForm(null, null, FormMethod.Post))

{

    if (Model.myEmployees != null)

    {

        foreach (var item in Model.myEmployees)

        {

                        @Html.CheckBoxFor(modelItem => item.IsValid.Value, new { id = item.EmployeeID })

                        @Html.DisplayFor(modelItem => item.FirstName)

        }

    }

}

No comments:

Post a Comment