要在ASP.NET Core MVC的ViewComponent内部生成HTML,可以按照以下步骤进行:
public class MyViewComponent : ViewComponent
{
public IViewComponentResult Invoke()
{
return View();
}
}
This is the ViewComponent content
Some additional HTML here
My Page
@await Component.InvokeAsync("MyViewComponent")
这样,当访问包含ViewComponent的视图时,将在页面中呈现ViewComponent的HTML内容。您可以根据需要在ViewComponent类的Invoke方法中添加逻辑来动态生成HTML。