I am creating a new .NET 6.0 application in Visual Studio 2022. When I run the default HomeController, the application is throwing a runtime exception saying index.cshtml was not found. But in the Views folder, I am able to see that file.


program.cs:
var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run(); HomeController.cs:
using Microsoft.AspNetCore.Mvc; using System.Diagnostics; using WebApplication3.Models; namespace WebApplication3.Controllers { public class HomeController : Controller { private readonly ILogger _logger; public HomeController(ILogger logger) { _logger = logger; } public IActionResult Index() { return View(); } public IActionResult Privacy() { return View(); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } } }
Источник: https://stackoverflow.com/questions/780 ... -not-found
Мобильная версия