This project is read-only.
1

Closed

Support Nullable booleans

description

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 4:30 PM by RichardPawson

comments

KieranH wrote Dec 11, 2013 at 9: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 10:29 AM

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

http://shamsmi.blogspot.co.uk/2008/12/tri-state-checkbox-using-javascript.html

scascarini wrote Jan 6, 2014 at 5: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 11:47 AM

Also implemented nullable booleans as action parameters with same semantics.