.net 5.0 mvc 中使用 Areas

时间:2021-08-20 15:44:21   收藏:0   阅读:26

项目总体文件结构

技术分享图片

 

 

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 测试

技术分享图片

 

原文:https://www.cnblogs.com/tomorrow0/p/15166189.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!