.net 5.0 mvc 中使用 Areas

项目总体文件结构

 

 

1 在项目中新建 Areas 文件夹
2 在 Areas 文件夹中新建 Orders 和 Products 文件夹
3 在 Orders 和 Products 文件夹下分别新建 Controllers 和 Views 文件夹
4 分别在 Orders 和 Products 文件夹下的 Controllers 文件夹中添加控制器并在控制器中对应添加 Area("Orders") 和 Area("Products") 特性

 

 


5 在Startup.cs 中的Configure方法中的app.UseEndpoints注册路由
endpoints.MapControllerRoute(
name: "MyArea",
pattern: "{area:exists}/{controller}/{action=Index}/{id?}");

6 测试

 

posted @ 2021-08-20 13:57  温故纳新  阅读(108)  评论(0)    收藏  举报