'Default .Net 6 MVC Web App Template: The view 'Index' was not found

I created a brand new web app in VS2022 using the "ASP.Net Core Web App (Model-View-Controller)" Template in .Net 6

I ran the application and got this error:

InvalidOperationException: The view 'Index' was not found.

I haven't changed any of the template code.

Very strange...



Solution 1:[1]

I've found one way to get it working...although its not clear to me why this works:

Add this package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation

and then change services.AddControllersWithViews() in Program.cs

builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JTech