07-23-2023, 07:56 AM
I am using MVC6 and have a checkbox input field in my form, but when the form is submitted the value for the checkbox always gets passed to the ViewModel as false:
**Here is how the property is declared in my ViewModel:**
[Display(Name = "Include Sales Tax")]
public bool IncludeSalesTax { get; set; }
**Here is how the form looks in my MVC6 razor form:**
<div class="form-group">
<div class="checkbox">
<label><input asp-for="IncludeSalesTax" type="checkbox" value="">@Html.DisplayNameFor(m => m.IncludeSalesTax)</label>
</div>
</div>
I figured the above would be the best way to follow Twitter Bootstrap standards and use the ASP.NET MVC6 asp-for tag for model binding.
When I submit the form the value for IncludeSalesTax is always false, even when checked. What am I doing wrong?
**Here is how the property is declared in my ViewModel:**
[Display(Name = "Include Sales Tax")]
public bool IncludeSalesTax { get; set; }
**Here is how the form looks in my MVC6 razor form:**
<div class="form-group">
<div class="checkbox">
<label><input asp-for="IncludeSalesTax" type="checkbox" value="">@Html.DisplayNameFor(m => m.IncludeSalesTax)</label>
</div>
</div>
I figured the above would be the best way to follow Twitter Bootstrap standards and use the ASP.NET MVC6 asp-for tag for model binding.
When I submit the form the value for IncludeSalesTax is always false, even when checked. What am I doing wrong?