我试图在本地主机上运行我的 asp.net 应用程序,但似乎出现以下错误:
处理请求时发生未处理的异常。
InvalidOperationException:未找到视图“索引”。搜索了以下位置:
/Views/Web/Index.cshtml
/Views/Shared/Index.cshtml
/Pages/Shared/Index.cshtml
我的观点位于Views > Web > Index.cshtml,尽管我仍然没有找到解决此问题的方法。我已经阅读了 asp.net 文档和其他 stackoverflow 帖子。似乎无法解决问题。
使用:
这是我的program.cs文件中的代码
using UploadExcel.Context;
using UploadExcel.Service;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddDbContext<DatabaseContext>();
builder.Services.AddScoped<IWebService, WebService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Web}/{action=Index}/{id?}");
});
app.MapRazorPages();
app.Run();
Run Code Online (Sandbox Code Playgroud)