Load ViewComponent via Jquery-GET (only partial html)

时间:2018-06-19 11:13:23

标签: jquery asp.net-core-mvc asp.net-core-viewcomponent

I need to load my ViewComponents at runtime by selecting it out of a select-control.

The problem I face is, that the ViewComponent returns the full HTML page and not only the PartialView I need.

Javascript:

$.get("/MyComponent/Invoke", (html) => { console.log(html);});

ViewComponent:

 public class MyComponentViewComponent : ViewComponent
{
    private LoadData LoadData { get; }

    public FavoritenViewComponent(LoadData loadData)
    {
        LoadData = loadData;
    }

    public IViewComponentResult Invoke()
    {
        var data= LoadData.List(_viewContext);

        return View(data);
    }
}

Is there any possibility to just return the partial view that is defined in the Default.cshtml file of the ViewComponent?

0 个答案:

没有答案