I'm working on an ASP.NET MVC app. The model for my form looks like the following:
public class ViewModel
{
public bool IsActive { get; set; }
}
In my form, I have the following HTML.
<label class="checkbox pull-left">
<input type="checkbox" id="IsActive" name="IsActive" data-val="true" data-val-required="The IsActive field is required.">
<i></i>Active/Deactive
<input name="IsActive" type="hidden">
</label>
When I post the form, the IsActive value in the model is always false. However, the Name property in the model has a value. I've tested this by setting a breakpoint in the following:
[HttpPost]
public ActionResult MyAction(ViewModel model)
{
// model.IsActive always is false
}
Why isn't the Checkbox value getting set?
What should I do to fix this?