This is a migrated thread and some comments may be shown as answers.

[Solved] Invalid value for Dropdownlist bound to nullable enum property in model

0 Answers 139 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Attila
Top achievements
Rank 1
Attila asked on 29 Sep 2011, 09:27 PM

Hi!

I've a problem with the Telerik Dropdown component.

In my model the dropdown is rendered with this code:

@Html.Telerik().DropDownListFor(m => m.CoOwnerIdentifierDocumentType).BindTo(IdentifierDocumentTypeValueDescriptionProvider.Values.AddPleaseSelect(false)).Value(Model.CoOwnerIdentifierDocumentType == null ? null : Model.CoOwnerIdentifierDocumentType.ToString())

Some facts about what is what here:
- CoOwnerIdentifierDocumentType is a nullable enum type in the Model.
- The values coming from IdentifierDocumentTypeValueDescriptionProvider which provides a list of SelectListItems where the Value contains the textual representation of the enum member like "DrivingLicense" and the display text contains the localized text of that member.
- A "Please select" item is added to that list because it's nullable. The value for that item is null.

As I see you're generating an INPUT type TEXT element, and the problem I'm have is that if I submit my form I got an error message that "Please select" is not a valid value...

The problem caused by is that not a hidden field is used for the value provider but the input element itself.

What is the preferred way to bind to a nullable enum model member which has additional element(s) in the list?

Thanks,
Attila

Tags
ComboBox
Asked by
Attila
Top achievements
Rank 1
Share this question
or