(I don't like dropdowns)Dropdown doesn't show selected value

Camillia
Camillia used Ask the Experts™
on
Dropdown is my least favorite control :)

This is MVC/C#.

This is the code
<select class="form-control zone1" name="Schedules[@i].DefaultTimeZone">
				@{
						var selectedId = anySavedSchedules ? item.DefaultTimeZone : Model.UserDefaultTimezone;
						foreach (var zone in ViewBag.Timezones)
							{

							<option @(zone.Id == selectedId ? "selected=\"selected\"" : "") value="@zone.Id">@zone.DisplayName</option>
							}
					}
				</select>

Open in new window


I see the "selected" but when the page loads, I don't see the value in the dropdown What am I missing?

ddl.png
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Co-Founder and Chief Architect
Top Expert 2016
Commented:
You shouldn't need selected=""selected"", just selected should be fine.

<option @(zone.Id == selectedId ? "selected" : "") value="@zone.Id">@zone.DisplayName</option>

Open in new window


But, it should still show the selection.  Something in JS or CSS somewhere that doesn't like that?  In the console, if you grab the element can you return the selected value?
Let me take a look again. I'll copy the select element from Console to another page and see if that works.
Something in JS or CSS somewhere that doesn't like that?

Yes, JS code was causing it to reset. Thanks for your help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial