Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
pass dropdown list value from view to controller and resend The same view in asp.net core 3.1?

View :

  <select id="count" name="count" class="form-control">
       <option value="0">Choose</option>
       <option value="2">two</option>
       <option value="3">three</option>
       <option value="4">four</option>
       <option value="5">five</option>                                    
  </select>

Jquery:

 <script>  
    $("#count").change(function () {
        let count = $("#count :selected").val();
        if (count != 0) {
            $.getJSON("/AdminPanel/Poll/Create/" + count);
        }
    });
</script>

Controller :

 public IActionResult Create(int id)
    {
        ViewBag.Count = id;

        return View();
    }

How can Send Value As Viewbag to View From Controller?

I want use in loop... in razor page

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can't. What I'd recommend is having a separate action method:

public IActionResult Create(int id)
{
    return Json(new { count = id });
}

And then in the GET request:

$("#count").change(function () {
    let count = $("#count :selected").val();
    if (count != 0) {
        $.getJSON("/AdminPanel/Poll/Create/" + count, function(d) {
             $("#count").val(d.count);
        });
    }
});

It's essentially syncing the two results by updating the server and refreshing the UI on the client. ViewBag is not recognized in the JavaScript callback, but you can return whatever you want and then make the update in JS. You can return a PartialView to replace part of the HTML page, for instance.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda