Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!