更新时间:2023-02-24 10:49:57
您不能通过属性路由来做到这一点,请通过MVC4方式做到这一点:
You can't do this with Attribute routing, do this the MVC4 way:
像这样在您的routemapper中映射一条路线:
Map a route in your routemapper like this:
routes.MapRoute("RouteName","{*url}",new { controller = "YourFancyController", action = "YourAction" });
这将是您的全部路线.
如果您想将所有路由映射到其控制器,则可以执行以下操作:
If you would like to map all the routes to their controller you can do this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
AreaRegistration.RegisterAllAreas();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
}