我創建了一個非常簡單的視圖組件(/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 關注
- 94 瀏覽
添加回答
舉報
0/150
提交
取消