1

在重新发明轮子之前(不确定在这种情况下是否可能!),是否有一段代码显示如何在 Tag Helper 实现中调用 ViewComponent?

编辑:包括泰勒谈话中的代码

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);
}
4

0 回答 0