ASP.NET MVC路由:如何命名与URL完全不同的操作

Meg*_*att 0 asp.net-mvc custom-routes

这是我以前的几个问题的延续.我有一个名为UserController的控制器,我想处理两种类型对象的操作:User和UserProfile.在其他操作中,我想为这两个对象和UserController定义一个Edit操作.它们需要是单独的动作,我不介意在控制器中将它们称为EditUser和EditProfile ,但我更喜欢URL如下所示:

http://www.example.com/User/Edit/{userID}
Run Code Online (Sandbox Code Playgroud)

http://www.example.com/User/Profile/Edit/{userProfileID}
Run Code Online (Sandbox Code Playgroud)

有没有人知道如何实现这些路线,因为对同一控制器中的动作有所限制?

对于上下文,以前的问题在这里这里

谢谢.

Rob*_*Rob 6

只是一个建议,但你不能做这样的事情来映射正确的路线?

routes.MapRoute(
    "ProfileRoute", // Route name
    "User/Edit/{userProfileID}", // URL with parameters
    new { controller = "User", action = "EditUser" } // Parameter defaults
);

routes.MapRoute(
    "ProfileEditRouet", // Route name
    "User/Profile/Edit/{userProfileID}", // URL with parameters
    new { controller = "User", action = "Editprofile" } // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud)

编辑:然后在你的控制器中创建两个单独的方法,称为EditUser(guid userId)和Editprofile(guid userId)