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)
有没有人知道如何实现这些路线,因为对同一控制器中的动作有所限制?
谢谢.
只是一个建议,但你不能做这样的事情来映射正确的路线?
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)
| 归档时间: |
|
| 查看次数: |
201 次 |
| 最近记录: |