Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 更改routeconfig中的操作名称_Asp.net Mvc_Routing_Asp.net Mvc Routing - Fatal编程技术网

Asp.net mvc 更改routeconfig中的操作名称

Asp.net mvc 更改routeconfig中的操作名称,asp.net-mvc,routing,asp.net-mvc-routing,Asp.net Mvc,Routing,Asp.net Mvc Routing,我试图用一些随机字符串替换默认的操作名称 例如,在下面的代码中,我对控制器名称执行此操作,它可以工作: routes.MapRoute( name: "test", url: "randomstring/{action}",//this works defaults: new { controller = "WorkRoles", action = "DisplayListOfRolesUser", id

我试图用一些随机字符串替换默认的操作名称

例如,在下面的代码中,我对控制器名称执行此操作,它可以工作:

routes.MapRoute(
               name: "test",
               url: "randomstring/{action}",//this works
               defaults: new { controller = "WorkRoles", action = "DisplayListOfRolesUser", id = UrlParameter.Optional }
           );
我只是想对动作名称做同样的处理,所以在URL中我有类似于
site.com/changed action name

这可以通过路由实现吗

有人能帮忙吗?

你是说这个吗

 routes.MapRoute(
                name: "Default",
                url: "changed-action-name",
                defaults: new { controller = "WorkRoles", action = "DisplayListOfRolesUser", id = UrlParameter.Optional }
            );

每当我进入
site.com/changed action name

时,这将带我进入操作
DisplayListOfRolesUser
和控制器
WorkRoles
。你有什么问题?当我尝试像{action}/newActionName这样的东西时,它不会像我希望的那样工作。我不知道你在说什么。@我在片段下面说明了我想要实现什么,在你上面的评论中,我描述了我是如何实现它的,即url:“{action}/newActionName”,。什么是newActionName?{action}将引导您采取行动,那么为什么要使用newActionName呢?