質問

I'm populating a drop down list using this code (and it works fine):

@Html.DropDownListFor(x => x.SelectedCountry, new SelectList(Model.Countries, "Value", "Text"), "Please Select a Country")

Sometimes, this view also gets data of a pre-selected country, so I want to select that country.

I tried:

@Html.DropDownListFor(x => x.SelectedCountry, new SelectList(Model.Countries, "Value", "Text", "United States"), "Please Select a Country")

But this didn't work. I also tried the value of the item, and no luck.

What am I doing wrong?

Also, is there a way to access / modify that element after creation? (using C# not javascript)

Thanks!

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top