I am generating HTML using JS innerhtml. The html is a select input with data from a Viewbag. When the select is generated there are no elements in it.

The exact same select input works if not generated by innerhtml.

for (i = 1; i <= memberCount; i++) {
        fullMemberHTML +=
        (
            '<div class="dropdown">' +
            '<select asp-for="Name" class="form-control" asp-items="ViewBag.Name" id="umaModelSelection" onchange="updatePercentages()"><option value="none">Select one</option></select>' +
            '</div>'
        );
    }

    document.getElementById("memberInfo").innerHTML = fullMemberHTML;

When I run the generated HTML by JS innerhtml, the select shows up but with only one content. I am trying to get it to populate using the Viewbag.Name contents.

Please note the select gets the Viewbag contents if not generated by JS innherhtml

Thank you for all your help

0 Answers