Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Studio
  4. ASP CORE Razor page, variable viewbag filter content with dropdownlist

ASP CORE Razor page, variable viewbag filter content with dropdownlist

Scheduled Pinned Locked Moved Visual Studio
javascriptasp-nethtmlquestion
3 Posts 3 Posters 36 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yayo_Arg
    wrote on last edited by
    #1

    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.

    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);
            }
    
        
    
    
    
                Contrato  
            
            @\*--------------------Listado desplegable de Contrato--------------------------\*@
            @Html.DropDownList("ddlSelContrato", new SelectList(ViewBag.SelContrato, "Id", "Nombre"), new { Class = "ddlStyle", onchange = "SelectedIndexChanged(this.value ,id)" })
        
        
    
        
    
                Proyecto  
            
            @\*--------------------Listado desplegable de Proyecto--------------------------\*@
            @Html.DropDownList("ddlSelProyecto", new SelectList(ViewBag.SelProyecto, "Id", "Nombre"), new { Class = "ddlStyle", onchange = "SelectedIndexChanged(this.value ,id)"})
        
    
        
    
                Punto de Medicion  
            
            @\*--------------------Listado desplegable de Puntos de estudio--------------------------\*@
            @Html.DropDownList("ddlPtoStudi
    
    L Richard DeemingR 2 Replies Last reply
    0
    • Y Yayo_Arg

      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.

      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);
              }
      
          
      
      
      
                  Contrato  
              
              @\*--------------------Listado desplegable de Contrato--------------------------\*@
              @Html.DropDownList("ddlSelContrato", new SelectList(ViewBag.SelContrato, "Id", "Nombre"), new { Class = "ddlStyle", onchange = "SelectedIndexChanged(this.value ,id)" })
          
          
      
          
      
                  Proyecto  
              
              @\*--------------------Listado desplegable de Proyecto--------------------------\*@
              @Html.DropDownList("ddlSelProyecto", new SelectList(ViewBag.SelProyecto, "Id", "Nombre"), new { Class = "ddlStyle", onchange = "SelectedIndexChanged(this.value ,id)"})
          
      
          
      
                  Punto de Medicion  
              
              @\*--------------------Listado desplegable de Puntos de estudio--------------------------\*@
              @Html.DropDownList("ddlPtoStudi
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Why have you posted this in the Visual Studio forum? It is clearly an ASP.NET or Javascript question.

      1 Reply Last reply
      0
      • Y Yayo_Arg

        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.

        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);
                }
        
            
        
        
        
                    Contrato  
                
                @\*--------------------Listado desplegable de Contrato--------------------------\*@
                @Html.DropDownList("ddlSelContrato", new SelectList(ViewBag.SelContrato, "Id", "Nombre"), new { Class = "ddlStyle", onchange = "SelectedIndexChanged(this.value ,id)" })
            
            
        
            
        
                    Proyecto  
                
                @\*--------------------Listado desplegable de Proyecto--------------------------\*@
                @Html.DropDownList("ddlSelProyecto", new SelectList(ViewBag.SelProyecto, "Id", "Nombre"), new { Class = "ddlStyle", onchange = "SelectedIndexChanged(this.value ,id)"})
            
        
            
        
                    Punto de Medicion  
                
                @\*--------------------Listado desplegable de Puntos de estudio--------------------------\*@
                @Html.DropDownList("ddlPtoStudi
        
        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        You need to make an AJAX call to load the filtered list when the parent list changes: Cascading Dropdowns With AJAX in Razor Pages | Learn Razor Pages[^]


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups