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

[Solved] DropDownList returns Text rather than Value on postback

0 Answers 31 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.
Theo
Top achievements
Rank 1
Theo asked on 08 Sep 2011, 02:41 PM
Have encountered a problem when binding a dropdownlist in MVC 2  with Teleric.Web.mvc 2011.2.712.235

<%= Html.Telerik.DropDownListFor(Function(b) b.PaymentTypeID) _
                         .BindTo(Model.GetPaymentTypeOptions) _
                         .HtmlAttributes(New With {.style = "width: 100%"})

And the GetPaymentTypeOptions returns a list of SelectListItem (Text, Value)
"<None>",Nothing
"Account", "PT000002"
"At Departure", "PT000003"
"Before Departure","PT000001"
"Insurance Claim","PT000004"

When I show the view with a model that contains PaymentType = Nothing then it displays the the dropdown with <None> which is correct. However when I then post back without making any changes I get the text value back in the PaymentTypeID rather than the Nothing. When changing the dropdown to Account and then back to <None> this behaviour does not occur. Can anyone tell me how to prevent this behaviour? Now I have to parse the ID against the "<None>" return value and reset it to Nothing. Have also tried the same with a list that had the empty string rather than the Nothing, but gave same erronous behaviour. 

Regards,
Theo
Tags
ComboBox
Asked by
Theo
Top achievements
Rank 1
Share this question
or