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呢?