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

233
Vistas
Ajax with ViewComponent

How to use AJAX for ViewComponent in Asp.Net Core? That is calling the method @Component.Invoke ("ComponentName", SomeData); ViewComponent will involve various views depending on SomeData without rebooting the main view.

Update

My solution is:

$(function () {
      $(Container).load('ControllerName/ControllerAction', {
                ArgumentName: ArgumentValue });
                                                 });

Controller :

public IActionResult ControllerAction(string value)
        {
           return ViewComponent("ViewComponent", value);
        }

Is there a way to directly use a ViewComponent as AjaxHelpers in previous versions?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Your solution is correct. From the docs:

[ViewComponents are] not reachable directly as an HTTP endpoint, they're invoked from your code (usually in a view). A view component never handles a request.

While view components don't define endpoints like controllers, you can easily implement a controller action that returns the content of a ViewComponentResult.

So as you suggested, a lightweight controller can act as an AJAX proxy to our ViewComponent.

public class MyViewComponentController : Controller 
{
    [HttpGet]
    public IActionResult Get(int id) 
    {
        return ViewComponent("MyViewComponent", new { id });
    }
}
over 4 years ago · Santiago Trujillo 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