zoukankan      html  css  js  c++  java
  • asp.net core 区域路由

    Areas 提供了一种把大型 ASP.NET Core MVC Web 应用程序分为较小的功能分组的方法,用到了区域那区域路由就必不可少,下面简单实现区域路由的两种方式

    1 此方式必须给控制器加上区域属性,也就是路由会自动匹配所有添加路由属性的controller

     1 //路由
     2 routes.MapRoute(name: "areaRoute",
     3                     template: "{area:exists}/{controller=MyHome}/{action=Index}");
     4                     
     5 //controller添加属性
     6     [Area("Manage")]
     7     public class UserInfoController : Controller
     8     {
     9         private readonly IUnitOfWork _unitOfWork;
    10         private readonly IUserInfoService _userInfoService;
    11 
    12         public UserInfoController(IUserInfoService userInfoService, IUnitOfWork unitOfWork)
    13         {
    14             _unitOfWork = unitOfWork;
    15             _userInfoService = userInfoService;
    16         }
    17         public IActionResult Index()
    18         {
    19             return View();
    20         }
    21    }

    2 此路由方式不需要给 控制器添加区域属性[Area("Manage")],也就是每添加一个区域就要为该区域添加一个路由方式

    1   routes.MapAreaRoute("Manage_route", "Manage",
    2                      "Manage/{controller=MyHome}/{action=Index}/{id?}"
    3                      );
  • 相关阅读:
    hdu 2222 Keywords Search
    Meet and Greet
    hdu 4673
    hdu 4768
    hdu 4747 Mex
    uva 1513 Movie collection
    uva 12299 RMQ with Shifts
    uva 11732 strcmp() Anyone?
    uva 1401
    hdu 1251 统计难题
  • 原文地址:https://www.cnblogs.com/wodemingtian/p/8995186.html
Copyright © 2011-2022 走看看