Visual Studio 2022中Controller无法找到View 'Create'的问题求助
问题:InvalidOperationException: 未找到视图 'Create'
异常信息
InvalidOperationException: 未找到视图 'Create'。已搜索以下位置:
异常截图
已尝试的解决方案
- 安装NuGet包:
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation、Microsoft.CodeAnalysis.Compilers、Microsoft.Net.Compilers.Toolset,均无效 - 将VS 2022更新至最新版本
- 尝试论坛上的所有相关解决方案
相关代码
Program.cs
var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation(); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); } app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseRouting(); app.UseAuthorization(); app.MapControllerRoute( name: "champ", pattern: "{controller=Champ}/{action=Index}/{id?}"); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.MapRazorPages(); app.Run();
ActionLinks 代码
@{ foreach (var item in Model.listSections) { <table class="table table-sm small " style="background-color:@item.section_color1;"> <tbody> <tr> <td class="text-center" style="width:25px;">@item.id_section</td> <td class="text-left" style="width:150px;">@item.section_name</td> <td class="text-center" style="width:60px;">@item.section_color1</td> <td class="text-center" style="width:60px;">@item.section_color2</td> <td class="text-center" style="width:30px;">@Html.ActionLink("New","Create","Champ",null)</td> </tr> </tbody> </table> foreach (var citem in Model.listChamps.Where(citem => citem.id_section == item.id_section).ToList()) { <table class="table table-sm small" style="background-color:@item.section_color2;"> <tbody> <tr> <td class="text-center" style="width:15px;"> </td> <td class="text-center" style="width:25px;">@citem.id_champ</td> <td class="text-left" style="width:150px;">@citem.champ_name</td> <td class="text-center" style="width:45px;">@citem.is_active</td> <td class="text-center" style="width:60px;">@citem.prefix</td> <td class="text-center" style="width:30px;">@Html.ActionLink("Edit","Edit","Champ",null,new {id = citem.id_champ })</td> </tr> </tbody> </table> } } }
文件夹结构
我已为此困扰数小时,恳请帮助指出问题所在。
内容的提问来源于stack exchange,提问作者Polyzack
相关产品推荐
相关产品推荐

