DmitryEfimenko / TwitterBootstrapMvc

Fluent implementation of ASP.NET-MVC HTML helpers for Twitter Bootstrap.
Apache License 2.0
224 stars 79 forks source link

DropDownList default value coming from previous DropDownList #390

Open JOldak opened 9 years ago

JOldak commented 9 years ago

I have a block of code that has the same options for multiple questions, a bit like like this:

Html.Bootstrap().DropDownListFor(m => m.HowOftenCycle, Model.HowOftenOptions).OptionLabel("")
Html.Bootstrap().DropDownListFor(m => m.HowOftenBus, Model.HowOftenOptions).OptionLabel("")
Html.Bootstrap().DropDownListFor(m => m.HowOftenTrain, Model.HowOftenOptions).OptionLabel("") 

HowOftenCycle, HowOftenBus, HowOftenTrain are all Strings.

This works great, unless HowOftenBus or HowOftenTrain are null, in which case the default value of the drop down is being set to the value from the previous form element.

It works fine if HowOftenBus or HowOftenTrain are empty string instead of null.

For now I have a workaround in the view model, a bit like the following. But a proper fix would be good :-)

if (HowOftenBus == null) HowOftenBus = "";
if (HowOftenCycle == null) HowOftenCycle = "";
if (HowOftenTrain == null) HowOftenTrain = "";

Thanks

Joe

DmitryEfimenko commented 9 years ago

Thanks for reporting this. I'll take a look what's going on.