VS2022+.NET6新建asp.net core mvc工程无法启动
VS2022+.NET6新建asp.net core mvc工程无法启动
报以下错误
An unhandled exception occurred while processing the request.
InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Views/Home/Index.cshtml
/Views/Shared/Index.cshtml
/Views/Home/Index.cshtml
/Views/Shared/Index.cshtml
Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable<string> originalLocations)
Stack
InvalidOperationException: The view 'Index' was not found. The following locations were searched: /Views/Home/Index.cshtml /Views/Shared/Index.cshtml
解决办法:
https://www.5axxw.com/questions/content/3p4al1
添加这个包Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
然后在Program.cs中改变services.AddControllersWithViews()
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();