Support Nullable booleans


This means specifically at the UI: where you want to force the user to decide whether they want to enter true or false, or (if Optional) to leave it unspecified (null) , rather than having a default value.
Closed Mar 21, 2014 at 3:30 PM by RichardPawson


KieranH wrote Dec 11, 2013 at 8:38 AM

To expand slightly on this issue

A boolean value can be set to null when inserting a record even when that column has a default. This occurs when the property is not explicitly set before saving the record.

Then, when attempting to edit a record with a null boolean value, the edit form throws the following error in Views\Shared\ObjectEditControl.ascx

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 27: FormMethod.Post,
Line 28: new {@class = IdHelper.EditName})) {%>
Line 29: <%:Html.PropertyListEdit(Model)%>
Line 30: <%}%>
Line 31:

RichardPawson wrote Dec 16, 2013 at 9:29 AM

Here's an implementation of a tri-state checkbox using JavaScript:


scascarini wrote Jan 6, 2014 at 4:15 PM

Implemented using the standard ASP.Net pattern, ie when editing a bool? a dropdown is shown with values "Unset", "True", "False". These values are in the resource dll.

The property must be marked as [Optionally] for the 'Unset' value to be accepted.

When viewing the bool? it shows as a ticked checkbox for true, unticked for false and an empty field for null. It could show Unset/True/False - this for discussion.

scascarini wrote Jan 7, 2014 at 10:47 AM

Also implemented nullable booleans as action parameters with same semantics.