サーバー側:「IEnumerable」型の ViewBag を作成します
Cliectside: ViewBag を反復処理して、ドロップダウンを構築します。
JavaScript/jQuery で SelectListItems を反復するにはどうすればよいですか?
Firefox エラー メッセージ:「TypeError: list.each は関数ではありません」
function test() {
var modtagerId = $('#ModtagerId');
modtagerId.empty();
// ViewBag.dropdownModtagerListeNyhedsbrev is of type "IEnumerable<SelectListItem>"
var list = ViewBag.dropdownModtagerListeNyhedsbrev;
list.each(function () {
$("<option />", {
val: this.value,
text: this.text
}).appendTo(modtagerId);
});
}