ASP.NET MVC路线:如何命名的动作的东西比在URL完全不同 [英] ASP.NET MVC Routes: How to name an action something completely different than in URL

查看:150
本文介绍了ASP.NET MVC路线:如何命名的动作的东西比在URL完全不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一对夫妇previous问题,我有一个延续。我有一个叫做UserController的控制器,我想对两种类型的对象处理措施:用户和用户配置。在其他的行动,我想定义这两个对象的编辑操作,并在UserController的。他们需要是单独行动的,我不介意叫他们EditUser和EditProfile在控制器的,但我preFER如果该URL的是这样的:

This is a continuation of a couple of previous questions I've had. I have a controller called UserController that I'd like to handle actions on two types of objects: User and UserProfile. Among other actions, I'd like to define an Edit action for both of these objects, and within UserController. They'll need to be separate actions, and I don't mind calling them EditUser and EditProfile in the controller, but I'd prefer if the URL's looked like this:

http://www.example.com/User/Edit/{userID}

http://www.example.com/User/Profile/Edit/{userProfileID}

有谁知道如何实现这些航线,鉴于克制的行动相同的控制器是?

Does anyone know how to achieve these routes, given the restraint for the actions being in the same controller?

和上下文,previous问题是<一个href=\"http://stackoverflow.com/questions/4080224/asp-net-mvc-routes-how-to-define-custom-route\">here和<一个href=\"http://stackoverflow.com/questions/4080546/asp-net-mvc-routes-conflicting-action-names-with-custom-route\">here

And for context, previous questions are here and here

感谢。

推荐答案

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

Just an suggestion, but can't you do something like this to map the correct routes?

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
);

编辑:
然后在您的控制器创建两个单独的方法调用EditUser(GUID用户id)和Editprofile(GUID用户id)

Then in your controller create two seperate methods called EditUser(guid userId) and Editprofile(guid userId)

这篇关于ASP.NET MVC路线:如何命名的动作的东西比在URL完全不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆