I am trying to add items in a @Html.DropDownListFor
with jQuery but after adding them they don't appear. Looking at the inspector of Chrome to debug code all items are being added, but in page they don't appear. I tried to update the select after to add the items but it still doesn't work.
How could I fix this?
HTML
<div class="cols-sm-10">
<label for="@Html.IdFor(model => model.cartaoCheckout.ParcelamentoSelecionado)" class="cols-sm-2 control-label">Parcelas <img src="~/Imagens/required.png" height="6" width="6"></label>
<div class="input-group">
<div class="input-group-prepend w-75">
<span class="input-group-text" style="height:40px;"><i class="fa fa-list-ol"></i></span> @Html.DropDownListFor(model => model.cartaoCheckout.ParcelamentoSelecionado, Model.cartaoCheckout.Parcelamentos, "-Parcelamento-", new { Class = "form-control" })
</div>
@Html.ValidationMessageFor(model => model.cartaoCheckout.ParcelamentoSelecionado, "", new { @class = "text-danger" })
</div>
</div>
jQuery
var dados = data["ParcelamentoCartao"];
var _select = $('#cartaoCheckout_ParcelamentoSelecionado');
_select.empty();
$.each(dados["Parcelamentos"], function(i, item) {
console.log(item.quantity);
_select.append('<option value="' + item.quantity + '">' + item.quantity + '</option>');
_select.trigger("liszt:updated");
_select.trigger("chosen:updated");
});
_select.trigger("liszt:updated");
_select.trigger("chosen:updated");
** EDIT - below the Chrome Inspect output**
<select class="form-control" data-val="true" data-val-number="The field Parcelamento must be a number." data-val-required="Informe o número de parcelas" id="cartaoCheckout_ParcelamentoSelecionado" name="cartaoCheckout.ParcelamentoSelecionado" style="display: none;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
Image with select empty even after execute jQuery
Here the image debugging Chrome's inspector. The select has the options added with jQuery