在重新发明轮子之前(在这种情况下不确定是否可能!),是否有一段代码显示如何在Tag Helper实现中调用ViewComponent?
编辑:包含来自泰勒talk
的代码private readonly IViewComponentHelper _viewComponentHelper;
public ShapeishTagHelper(IViewComponentHelper viewComponentHelper) {
_viewComponentHelper = viewComponentHelper;
}
[ViewContext]
public ViewContext ViewContext { get; set; }
public string Name { get; set; }
public int Age { get; set }
public override void Process(TagHelperContext, TagHelperOutput output) {
output.TagName = null;
((ICanHasViewContext)_viewComponentHelper).Contextualize(ViewContext);
var viewContent = _viewComponentHelper.Invoke("Shapeish", Name, Age);
output.Content.SetContent(viewContent);
}