Can I reload an asp 5/MVC 6 View Component via ajax? Can I reload an asp 5/MVC 6 View Component via ajax? ajax ajax

Can I reload an asp 5/MVC 6 View Component via ajax?


All you need to do is set up a route in a controller that returns the view component. For example:

public class MyController : Controller {    public IActionResult GetMyViewComponent() {        return ViewComponent("MyViewComponent", <arguments...>);    }}

You can then make a GET request to this controller via AJAX, and replace the old view component with the result of the request.

As for whether you should use a partial or view component, it is up to you, but I would recommend sticking with a view component because it allows you to keep the relevant logic for the search bar within the component itself.