daveaglick / FluentBootstrap

Provides extensions, helper classes, model binding, and other goodies to help you use the Bootstrap CSS framework from .NET code.
http://www.fluentbootstrap.com
MIT License
200 stars 76 forks source link

Set no default selection so only placeholder is shown #75

Closed Tsukasa42 closed 7 years ago

Tsukasa42 commented 7 years ago

Sorry if I'm missing something, I just discovered your work. Great job.

I'm looking to create a dropdown without a default selection.

With your framework it looks like I would need to use SelectFor.

@Html.Bootstrap().SelectFor(x => x.Account.JobTitle, Model.JobTitleList).SetControlLabel(null).AddAttribute("placeholder", "Job Title")

JobTitle has no value but of course the first one is being selected.

The ViewModel for the list is IEnumerable and the SelectList being passed into it has null set as the selected item.

Tsukasa42 commented 7 years ago

I managed to make the following work.

.AddOption(null).AddOptions(Model.JobTitleList)

Validation is still triggered with it set to null.