0
I have a select that is being populated via ajax, when opening the modal, I call the function that loads the select, and it is working perfectly.
But I need a cascade effect, in the first field, and when changing, it changes the input text according to the selected field. How can I do it? I’m trying to do it this way:
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 id 1 straight, 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 });
}
}
However it does not return me error, but also does not return me what I need.
It was not very clear, you want after selecting some item from
select
change the text of ainput
?– Barbetta
@Barbetta edited how I’m trying to do.
– Mariana