我怎样才能避免这样的路由配置?我有一个管理面板,具有管理员角色的用户可以对不同的实体(用户/配置文件/地址/...)执行一些操作(编辑/删除/查看)。我想把所有这些动作放到 1 个控制器中。
routes.MapRoute(
name: "EditProfile",
url: "Account/Profiles/{id}/Edit",
defaults: new { controller = "Account", action = "EditProfile" }
);
routes.MapRoute(
name: "RemoveProfile",
url: "Account/Profiles/{id}/Remove",
defaults: new { controller = "Account", action = "RemoveProfile" }
);
routes.MapRoute(
name: "EditAddress",
url: "Account/Addresses/{id}/Edit",
defaults: new { controller = "Account", action = "EditAddress" }
);
routes.MapRoute(
name: "RemoveAddress",
url: "Account/Addresses/{id}/Remove",
defaults: new { controller = "Account", action = "RemoveAddress" }
);
//...
基本上我想像这样将所有 MapRoute 替换为:
routes.MapRoute(
name: "AccountProfileActions",
url: "Account/{entities}/{id}/{subAction}",
defaults: new { controller = "Account", action = {subAction} + {entities}}
);
我怎样才能做到这一点?