且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何从的RouteData获取路线名称?

更新时间:2023-02-13 20:18:43

不幸的是,这是不可能得到路由的路由名称,因为该名称不是路由的属性。当添加路由到RouteTable,名字被用作路线内部指标,它永远不会公开。

Unfortunately, it's not possible to get the route name of the route because the name is not a property of the Route. When adding routes to the RouteTable, the name is used as an internal index for the route and it's never exposed.

有做到这一点的方法之一。

There's one way to do this.

当你注册一个路由,路由名称的路线上设置了DataToken并用它来过滤路由。

When you register a route, set a DataToken on the route with the route name and use that to filter routes.

做#1的最简单方法是可能会写自己的扩展方法映射路线。

The easiest way to do #1 is to probably write your own extension methods for mapping routes.