C# 在asp.net core上打开带有自定义路由的视图页
我在使用Asp.Net Core 3.1打开自定义路由的查看页面时遇到问题 BrandControllerC# 在asp.net core上打开带有自定义路由的视图页,c#,razor-pages,asp.net-core-3.1,ef-core-3.1,C#,Razor Pages,Asp.net Core 3.1,Ef Core 3.1,我在使用Asp.Net Core 3.1打开自定义路由的查看页面时遇到问题 BrandController [Area("CormComm")] [Route("CorpComm/[controller]/[Action]")] public class BrandController : Controller { private readonly CorpCommDbContext _context; public BrandContr
[Area("CormComm")]
[Route("CorpComm/[controller]/[Action]")]
public class BrandController : Controller
{
private readonly CorpCommDbContext _context;
public BrandController(CorpCommDbContext context)
{
_context = context;
}
这是我的文件结构
我在视图文件夹中添加了一个名为CorpComm的文件夹,并将Brand文件夹拖动到CorpComm中
然后我运行页面并转到https://localhost:44325/CorpComm/Brand/index
上面写着
InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Areas/CormComm/Views/Brand/Index.cshtml
/Areas/CormComm/Views/Shared/Index.cshtml
/Views/Shared/Index.cshtml
/Pages/Shared/Index.cshtml
查看页面结构:
控制器结构:
嗨,这是我的路由配置
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "corpcomm",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
});
请参见
区域
属性中的打字错误。有CormComm
,我想一定是CorpComm
。你也可以添加路由配置吗?必须有这样的东西endpoints.mapControllerOute(“区域”,“{area:exists}/{controller=Home}/{action=Index}/{id?}”)代码>嗨@SelimYıldız,我添加了我的路线configs@picolino嗨,我更新了打字错误,但有同样的错误