亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Razor Pages 在 Asp.NET Core 2.2 中找不到

使用 Razor Pages 在 Asp.NET Core 2.2 中找不到

C#
一只斗牛犬 2023-09-16 15:54:39
我創建了一個非常簡單的視圖組件(/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 回答

?
繁華開滿天機

TA貢獻1816條經驗 獲得超4個贊

確保組件視圖位于搜索路徑中,

并且在調用組件時只需使用不帶后綴的名稱

@await?Component.InvokeAsync("Menu")


查看完整回答
反對 回復 2023-09-16
  • 1 回答
  • 0 關注
  • 94 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號