.Net Core Mvc 发布版提示视图找不到

 

出错提示

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

 

posted @ 2021-02-23 13:14  delafqm  阅读(1543)  评论(0)    收藏  举报