0
I am trying to load a select via ajax, following as I am doing: HTML:
<select id="cbplanos" class="form-control"></select>
Controller Code:
public async Task<IActionResult> Load()
{
var lista = _context.PlanosServicos
.Select(x => new { x.Id, x.Descricao });
return Json(new { Resultado = lista });
}
And here’s the AJAX code:
function ListarItens() {
var url = "/PessoasServicos/Load";
$.ajax({
type: "get",
url: "/PessoasServicos/Load",
data: { tipos: $("#cbplanos").val() },
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (data) {
var selectbox = $('#cbplanos');
$.each(data, function (i, d) {
selectbox.append('<option value="' + d.Id + '">' + d.Descricao + '</option>');
});
}
});
}
But he’s not bringing me values. What I’m going through wrong?
Already inspected the object "date" in
success
? Seems to me you should weardata.Resultado
in theeach
– Ricardo Pontual
I tried this way, but continued with the same problem.
– Mariana
But if you inspect the "date" object, the data is being returned?
– Ricardo Pontual
It is now showing two items that are in this table Planosservicos, but in select appears as Undefined.
– Mariana