我创建了一个非常简单的视图组件(/ViewComponents/MenuViewComponent.cs):namespace MySite.ViewComponents{ public class MenuViewComponent : ViewComponent { public Task<IViewComponentResult> InvokeAsync() { return Task.FromResult((IViewComponentResult)View("Default")); } }}视图部分在这里(/Pages/Components/Menu/Default.cshtml):<div>Menu</div>我从文件中调用菜单,_Layout.cshtml如下所示:@await Component.InvokeAsync("MenuViewComponent");查看页面时,我收到以下错误消息:InvalidOperationException: A view component named 'MenuViewComponent' could not be found.A view component must be a public non-abstract class, not contain any generic parameters, and either be decorated with 'ViewComponentAttribute' or have a class name ending with the 'ViewComponent' suffix. A view component must not be decorated with 'NonViewComponentAttribute'.问题:为了让它正常工作,我缺少什么?
- 1 回答
- 0 关注
- 62 浏览
添加回答
举报
0/150
提交
取消