C# Url生成未根据路由配置提供所需结果

C# Url生成未根据路由配置提供所需结果,c#,asp.net,asp.net-mvc,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,我使用的是ASP.NETMVC4 我有一个名为Server的控制器,还有两个名为Search和Component的操作方法。我有以下路由配置: routes.MapRoute("Component", "{controller}/{serverId}/{action}", new { controller = "Server", action = "Component" }, new { serverId = @"\d+" }); 我正在寻找类似以下内容的url:

我使用的是
ASP.NETMVC4

我有一个名为
Server
的控制器,还有两个名为
Search
Component
的操作方法。我有以下路由配置:

routes.MapRoute("Component",
     "{controller}/{serverId}/{action}",
     new { controller = "Server", action = "Component" },
     new { serverId = @"\d+" });
我正在寻找类似以下内容的url:

/Server/12345/Component
我的搜索操作方法:

return RedirectToAction("Component", new { serverId = 12345 });
public ActionResult Component(int serverId)
{
     return View();
}
我的组件操作方法:

return RedirectToAction("Component", new { serverId = 12345 });
public ActionResult Component(int serverId)
{
     return View();
}
生成的url为:

/Server/12345/
这是错误的,它遗漏了“组件”。为什么会这样

     new { controller = "Server", action = "Component" },
由于您将默认操作设置为“组件”,我认为链接生成足够智能,可以将其关闭


由于您将默认操作设置为“组件”,我认为链接生成足够智能,可以将其关闭。

您将组件定义为默认操作,那么为什么要附加它?
若您希望它出现在路由中,那个么将其从默认值中删除并添加到您的RedirectToAction调用中。

您将组件定义为默认操作,那个么为什么要附加它呢?
如果您希望它出现在您的路线中,请将其从默认设置中删除,并将其添加到您的RedirectToAction调用中。

请注意,这是测试路线的好方法:请注意,这是测试路线的好方法: