我如何从的RouteData获取路线名称? [英] How do I get Route name from RouteData?

查看:240
本文介绍了我如何从的RouteData获取路线名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Global.asax中定义的几种途径;

I have several routes defined in my Global.asax;

当我是一个网页,我需要弄清楚什么是当前路由的路由名称上,因为路由名称驱使我的网站菜单。

When I'm on a page I need to figure out what is the route name of the current route, because route name drives my site menu.

如何才能做到这一点?

推荐答案

不幸的是,这是不可能得到路由的路由名称,因为该名称不是路由的属性。当添加路由到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.

这篇关于我如何从的RouteData获取路线名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆