【发布时间】:2021-06-21 04:16:47
【问题描述】:
我正在使用 ASP .Net Core ViewComponent,并且我有一个组件之间共享的公共功能,所以我决定制作一个公共 ViewComponent,所有其他组件都必须继承自它
我先试过了
public class CommonViewComponent: ViewComponent
{
//some methods
}
还有这样的子组件
public class SubDealsViewComponent: CommonViewComponent
{
public async Task<IViewComponentResult> InvokeAsync()
{
//calling some methods from the parent
}
}
在这种情况下,我遇到了父组件必须包含Invoke() 或InvokeAsync() 的错误
当我为父组件创建 Invoke() 方法时,我得到了这个错误
InvalidOperationException:查看组件 'Components.SubDealsViewComponent' 必须只有一个公共方法 命名为“InvokeAsync”或“Invoke”。
【问题讨论】:
标签: c# asp.net-core .net-5 asp.net-core-viewcomponent