coo*_*ryu 8 asp.net-core-mvc asp.net-core .net-6.0
我试图在本地主机上运行我的 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)
Nis*_*nga 11
如果您在Visual Studio 2022、ASP.Net Core MVC ( .NET 6 )上遇到此问题,作为立即解决方案,您可以打开*.csproj文件所在的终端并执行,
dotnet watch run
Run Code Online (Sandbox Code Playgroud)
如果您确实想使用 Visual Studio,则必须将 Visual Studio 2022 更新到版本 17.1.0 +(您当前的版本可能是 17.0.4 或其他版本)。参考这个和这个。
因为您正在使用控制器,所以您必须添加
builder.Services.AddControllersWithViews();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20286 次 |
| 最近记录: |