I made a component:
public class CatSearchComponent : ViewComponent
{
public async Task<IViewComponentResult> InvokeAsync()
{
return View();
}
}
@await Component.InvokeAsync("CatSearchComponent")
Within the component I have a button that I want to use jquery $.ajax to call a method and render some data within the component, e.g. an action called GetCats()
that returns some Json data.
It would be nice to put this method into the component since it's component specific.
However I am not sure what the url would be to put into my $.ajax call to call such a method, or even if it's allowed in MVC.
I could create a new controller and put an action on it to get the data but it would be nice if it was coupled with my ViewComponent. Is there a way to do this?