C# 从路由数据获取操作名称

C# 从路由数据获取操作名称,c#,asp.net-mvc-2,C#,Asp.net Mvc 2,我知道如果我想得到我可以使用的当前动作 ControllerContext.RouteData.GetRequiredString("action") 但是,如果我的路线允许http://mydomain/this 有空格 如何获得“此hass Spaces”而不是“此hass Spaces” 下面是我的路由表中的一个片段 routes.MapRoute( "ThisHasSpaces", // Route name "This

我知道如果我想得到我可以使用的当前动作

ControllerContext.RouteData.GetRequiredString("action")
但是,如果我的路线允许
http://mydomain/this 有空格

如何获得“
此hass Spaces
”而不是“
此hass Spaces

下面是我的路由表中的一个片段

        routes.MapRoute(
            "ThisHasSpaces", // Route name
            "This Has Spaces", // URL with parameters
            new { controller = "Home", action = "ThisHasSpaces", id = UrlParameter.Optional } // Parameter defaults
        );

如果您的路由看起来像这样,那么没有任何东西可以为您提供原始字符串(除了
Request.Uri
),因为您实际上没有将Uri映射到路由参数

由于您对路线进行了硬编码,因此可以添加另一个值:

    routes.MapRoute(
        "ThisHasSpaces", // Route name
        "This Has Spaces", // URL with parameters
        new { controller = "Home", action = "ThisHasSpaces", orgstring = "This Has Spaces", id = UrlParameter.Optional } // Parameter defaults
    );
然后取回它:

ControllerContext.RouteData.Values["orgstring"]

你真的得到了
这个hassspaces
?是的,我得到了,因为这是控制器中的动作名称,我的路由表将空格转换为非间隔版本