How to invoke a View Component from controller

前端 未结 5 1887
耶瑟儿~
耶瑟儿~ 2021-02-13 19:08

Is it possible to invoke a View Component from controller and render it to a string? I am really looking for some code example for this. Any help will be much appreciated.

5条回答
  •  天涯浪人
    2021-02-13 19:47

    Please refer to example from official ASP.NET article on ViewComponent

    In their example, the view component is called directly from the controller as follows:

    public IActionResult IndexVC()
    {
        return ViewComponent("PriorityList", new { maxPriority = 3, isDone = false });
    }
    

提交回复
热议问题