0
I have a view with dropDowlist that contains data that comes from the database and just below put a buttom that when I click will attach the selected dropdownlist item in a list, I made a code here but is not attaching, if I put predefined values works, but dropDowlist values do not.
javascript
$("#addPeca").click(function () {
var resultData = $("#ListaPecas option:selected").text();
$(document).ready(function () {
var myselect = $('<ul>');
$.each(resultData, function (index, key) {
myselect.append($('<li></li>').val(key).html(key));
});
$('#listPeca').append(myselect.html());
});
});
In my view
<div class="form-group">
@Html.LabelFor(model => model.ListaPecas, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.PecasId,Model.Pecas,"Pecas", new { @class = "form-control" } )
@Html.ValidationMessageFor(model => model.ListaPecas, "", new { @class = "text-danger" })
<button class="btn btn-info" type="button" id="addPeca">Adicionar</button>
</div>
</div>
List where the selected value will be attached
<ul id="listPeca"></ul>
managed to solve?
– Leandro Angelo