从ASP.NET MVC路由生成URL

Ric*_*ton 2 c# asp.net asp.net-mvc-routing asp.net-mvc-2

如果我有一些路线设置如下:

context.MapRoute("Route1", "Public/DataCapture/Name", new { controller = "Profile", action = "Name" } );

context.MapRoute("Route2", "Public/DataCapture/Age", new { controller = "Profile", action = "Age" } );

context.MapRoute("Route2", "Public/DataCapture/Amount", new { controller = "Income", action = "Amount" } );
Run Code Online (Sandbox Code Playgroud)

如何生成使用路径路径而不是实际控制器/操作路径的URL?

例如

Url.Action("Name", "Profile")
Run Code Online (Sandbox Code Playgroud)

应生成"Public/DataCapture/Name"而不是"Public/Profile/Name"

小智 7

尝试使用Url.RouteUrl.

在过去,当我遇到问题以返回正确的路线时,通常表明我的路线没有以正确的顺序定义,或者我正在做的事情使路由系统不符合我想要的路线.