Динамически возвращать SelectListItems от добавления в JQuery с помощью Razor (ASP. NET MVC / scaffolding) - PullRequest
0 голосов
/ 26 февраля 2020

У меня похожая проблема с этим человеком: https://forums.asp.net/t/1936849.aspx?+Html+ListBoxFor

ПРОСМОТР:

/*
//OLD
@Html.ListBoxFor(model => model.CompanySelectedList,
                 Model.CompanyList, // used to return a value for the user to select from
                 new { id = "ddlCompany", 
                       @name = "ddlCompany", 
                       @class = "EditableBox txtDropDownLong", 
                       @title = "Select Company" })
*/

<input id="auto_CompanyList" maxlength="100" name="Company List" type="text" class="EditableBox txtBox txtBoxLong" /> //this is the auto complete box

// NEW 
@Html.ListBoxFor(model => 
                   model.CompanySelectedList, 
                   new List<SelectListItem>(), // this looks like where the problem occurs, creating a new list that isnt mapped. 
                   new { id = "auto_CompanyHidden",
                        @name = "auto_CompanyHidden", 
                        @class = "EditableBox txtDropDownLong" ,
                        @style="display:none" })

Javascript:

// This is where the Dynamic items that will populate the SelectList comes from
select: function (event, ui) {
    $(".selectlist-list").append(
                    "<li class='selectlist-item' id ='" + ui.item.id + "|" + ui.item.territory + "' >" + ui.item.value
                    + "<button id='btnDeleteCompany' class='btnDeleteCompany' style='float: right;'>"
                    + "<button id='btnMainCompany' class='btnMainCompany' style='float: right;'></li>");

Я не могу передать данные в контроллер. Нужна помощь в отображении новых SelectList элементов, которые я динамически создаю в результате функции автозаполнения.

enter image description here

...