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

[Solved] Default value for DropDownListFor

1 Answer 242 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.
Derek Trickett
Top achievements
Rank 1
Derek Trickett asked on 01 Nov 2010, 04:46 PM
I am using the DropDownListFor helper, with a SelectList object containing a SelectListItem with Value = string.Empty and Text = "Please select one...".  This is representing nothing being selected in the list.  The value is eventually bound to a Nullable<int>.  In the previous release, this was working fine; if this object was the selected value of the DropDownListFor the Nullable<int> would be properly set to null.

It looks like for SP1 this fix has broken my usage: 
Fixed: ComboBox does not work with DropDownItems with Value property not set

Now the value being posted for my DropDownListFor is "Please select one..." instead of the expected/previously returned null.  Model binding returns an invalid ModelState as it is an invalid value for Nullable<int>.  

What is the recommendation for this functionality?

I attempted to change the SelectListItem to have both Value and Text equal to string.Empty, but when I do this the DropDownListFor has trouble rendering (the visible div is only 3-4 px in height).  

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 02 Nov 2010, 08:48 AM
Hello Derek,

The aforementioned fix allows to bind component to list of items, which does not have Value property. We decide to provide same behavior as HTML SELECT tag, which will send to the server Text value if Value property is not set.

In order to achieve your goal, I will suggest you set Value property of the dummy SelectListItem to "null" or "-1" depending on the type of the parameter, which Action method accepts.

Sincerely yours,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
Derek Trickett
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or