I have three dropdownlists that I fill with the contents of viewbag variables. I want the content of the second variable to be filtered when I select a value of the first using JQuery or javascript. The same with the third dropdownlist, which is filtered by what is selected in the second.
<script type="text/javascript">
function SelectedIndexChanged(accion, idnum) {
var nuevaSelProyecto = "";
var proyecto = "";
var nombre = "";
switch (idnum) {
case "ddlSelContrato": {
//var getValue = document.getElementById('ddlSelContrato').selectedOptions[0].value;
var e = document.getElementById("ddlSelContrato");
var getValue = e.options[e.selectedIndex].value;
nombre = "Contrato, indice seleccionado: " + getValue;
};
break;
case "ddlSelProyecto":
nombre = "Proyecto";
break;
case "ddlPtoStudio":
nombre = "Punto Estudio";
default:
nombre = "Defecto";
break;
}
alert("Alerta, indice: " + accion + " - " + nombre);
}
</script>
<div>
<text style="margin-left: 8px;">
  Contrato  
</text>
@*--------------------Listado desplegable de Contrato--------------------------*@
@Html.DropDownList("ddlSelContrato", new SelectList(ViewBag.SelContrato, "Id", "Nombre"), new { Class = "ddlStyle", onchange = "SelectedIndexChanged(this.value ,id)" })
</div>
<div>
<text style="margin-left: 8px;">
  Proyecto  
</text>
@*--------------------Listado desplegable de Proyecto--------------------------*@
@Html.DropDownList("ddlSelProyecto", new SelectList(ViewBag.SelProyecto, "Id", "Nombre"), new { Class = "ddlStyle", onchange = "SelectedIndexChanged(this.value ,id)"})
</div>
<div>
<text style="margin-left: 8px;">
  Punto de Medicion  
</text>
@*--------------------Listado desplegable de Puntos de estudio--------------------------*@
@Html.DropDownList("ddlPtoStudio", new SelectList(ViewBag.PtoStudio, "Id", "Nombre"), new { Class = "ddlStyle", onchange = "SelectedIndexChanged(this.value ,id)" })
</div>
Controller:
// GET: PuntoEstudios
public IActionResult Index()
{
ViewBag.SelContrato = _context.Contratos.OrderByDescending(x=>x.Nombre).ToList(); //Variable MVC donde paso a la vista el List de los Contratos
ViewBag.SelProyecto = _context.Proyectos.ToList(); //Variable MVC donde paso a la vista el List de los Proyectos
ViewBag.PtoStudio = _context.PuntoEstudios.ToList(); //Variable MVC donde paso a la vista el List de los pto de estudio
return View();
}
How can I do it without calling the server