【发布时间】:2017-04-27 19:40:55
【问题描述】:
我需要从派生的RazorPage 中获取视图组件的渲染结果。在 .cshtml 文件中,我可以做
@await Component.InvokeAsync("MyButton", new MyModel())
现在,如果我的剃须刀页面继承自这个类:
public class MyRazorPage<TModel> : RazorPage<TModel>
{
public async Task<HtmlString> GetViewComponentForExample()
{
// I cannot access the injected "Component" this way...
string temp = await Component.InvokeAsync("MyButton", new MyModel()).Result.WriteTo();
return new HtmlString(temp);
}
}
在上面的方法GetViewComponentForExample()我不能使用注入的Component属性。如何访问 Component 属性,或者如何完成上述操作?
【问题讨论】:
标签: c# razor asp.net-core-viewcomponent