How do I check if a checkbox value is true when the result is either {false} for not checked and {true,false} for checked? When I add value="yes" to the helper i get {yes,false} for checked. {Sidebar: What is so wrong with Microsoft they can't get this right?}
{Versions: netcoreapp3.1, Microsoft.EntityFrameworkCore 3.1.5, Microsoft.VisualStudio.Web.CodeGeneration.Design 3.1.3, VS Enterprise 2019 16.6.3}
View:
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="MyBoolValue" /> @Html.DisplayNameFor(model => model.MyBoolValue)
</label>
</div>
Controller: (with IFormCollection form)
if(form["MyBoolValue"].ToString() != "") // Does not work when the value is {false} not checked
{
DbTable.MyBoolValue = true;
}
else
{
DbTable.MyBoolValue = false;
}
I've tried many combinations like:
if(Convert.ToBoolean(form["MyBoolValue"]) == true)
Anyone have a simple way to get a true false condition consistently from a checkbox?