Search code examples
asp.net-coreasp.net-core-2.0asp.net-core-viewcomponent

Asp.net Core - How to InvokeAsync for a ViewComponent from javascript?


I have a simple ViewComponent (i.e. partialview) which i can do an InvokeAsyn() to render a small snippet of HTML by placing the invoke code within my CSHTML.

Question

How can I call a ViewComponent InvokeAsync (or any method) to retrieve raw data (not necessarily HTML markup) from javascript?

Alternatively

An alternative approach that could totally work is exposing an Asp.net Core API which i can simply call from javascript side.


Solution

  • You can not call view components using http(Ajax) but you can have action method on controller will can return view component out put as resut