出錯提示
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor[3] The view 'Index' was not found. Searched locations: /Views/Login/Index.cshtml, /Views/Shared/Index.cshtml
原因:
控制器沒有對應視圖,需要在運行時運態編譯生成 public IActionResult Index() { return View("AdminDefault"); //動態指向視圖 }
解決問題:
添加包
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
添加Startup.cs代碼,啟用運行時編譯,生產環境可用
services.AddRazorPages().AddRazorRuntimeCompilation();
參考
https://docs.microsoft.com/zh-cn/aspnet/core/mvc/views/view-compilation?view=aspnetcore-5.0&tabs=visual-studio
https://www.cnblogs.com/yyfh/archive/2020/02/27/12373249.html
