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

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
LVL 8
CamilliaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin SaundersDirector of OperationsCommented:
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?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CamilliaAuthor Commented:
Let me take a look again. I'll copy the select element from Console to another page and see if that works.
0
CamilliaAuthor Commented:
Something in JS or CSS somewhere that doesn't like that?

Yes, JS code was causing it to reset. Thanks for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.