How do I get Route name from RouteData?

前端 未结 10 905
猫巷女王i
猫巷女王i 2021-02-05 02:03

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

10条回答
  •  情深已故
    2021-02-05 02:35

    A simple approach that I've implemented is to supply a named key for the 'defaults' param of the .MapPageRoute method. Use a constant for the default, and you can pull it out of the Page.RouteData.Values collection the same way you would normally.

    example (vb.net)

    routes.MapPageRoute("league-division-stats", "{league}/{division}/stats", "~/routes/league-division-stats.aspx", False, New RouteValueDictionary(New With {.section = "stats"}))
    

    Page.RouteData.Values("section") gives me 'stats'

提交回复
热议问题