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

355
Vistas
AspnetCore MVC - Javscript code for loading parital view is not working

I am trying to load different partial views based on the value inside view bag and for that I have tried the following javascript method :

function CheckAction()
    {
        var cat = document.getElementById('CType').value;
        var op = document.getElementById('OType').value;



        if (op == "Add")
        {
            if (cat == "State")
            {
                @ViewBag.PartialView="_StatePartial";                  
            }
        }
    }

here is the link to the view(cshtml file) : https://pastebin.com/XZPJBwp4

I have debugged the code and found out that the js code is working properly and viewbag is also getting the data but the only problem is that, the partialview is not being loaded. By default, default partialview is being loaded but once the button is clicked, the partialview should be changed that is not happening. please refer to this (https://pastebin.com/XZPJBwp4) view file to get the better understanding.

Here is the server side code from where the partial view is getting value(Controller Method)

 [HttpGet]
    public IActionResult DataMgmt()
    {                         
           ViewBag.PartialView = "_DefaultDataMgmt";
           return View();          
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

My suggestion is that: The “ViewBag” is rendered at the same time as the page, so you can’t use this to load Partial View, I suggest you to use Ajax to achieve this function.

Delete the and send Ajax in JavaScript:

enter image description here

Receive the Ajax and return the Partial View

enter image description here

(Partial View)

enter image description here

Then you can load the Partial View

enter image description here

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