I have a select that is being populated via ajax, when I open the modal, I call the function that loads the select, and it is working perfectly.
But I need a cascade type effect in the first field, and when changing, it changes the input text according to the field selected. How can I do it? I'm trying to do this:
function Carrega(id) {
$.ajax({
type: "post",
url: "/PessoasServicos/CarregaDados",
data: { id },
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (data) {
var tipoplano = $('#txtTipoPlano');
tipoplano = data.resultado;
}
});
}
$('#cbplanos').on("click", function () {
Carrega(1);
});
I'm passing the direct id 1, to do a test, and here is the controller:
[HttpPost]
public ActionResult CarregaDados(int id)
{
try
{
var resultado = (from a in _context.PlanosServicos
where a.Id == id
select new
{
a.Tipo,
});
return Json(resultado);
}
catch (Exception ex)
{
return Json(new { Result = ex.Message });
}
}
But it does not return an error, but it does not return what I need.