I am new to WebForms for MVC. Do I have a view model field with type bool? and by default, EditorFor() displays this field as a DropDownList with the "Not set" option. I would prefer to display it as a CheckBox, and if the value is null, just set it to a checkbox.
The name of the field is RFP.DatesFlexible , and so I wrote the following markup in my view:
<input type="checkbox" id="RFP_DatesFlexible" name="RFP.DatesFlexible" /> <label for="RFP_DatesFlexible">My Dates are Flexible</label>
But that does not work. The result is always zero, and ModelState.IsValid is false.
Can anyone tell me how I could make this work?
EDIT
This is the code I ended up in, which works fine.
@Html.CheckBox("RFP.DatesFlexible", Model.RFP.DatesFlexible ?? false) @Html.Label("RFP.DatesFlexible", "My Dates are Flexible")
The shortcut is correctly linked to the check box, so clicking on the item will be toggled.
asp.net-mvc asp.net-mvc-3
Jonathan Wood Dec 13 2018-11-11T00: 00Z
source share