我正在使用ASP.NET MVC 4
。根据路由配置没有给出想要的结果的url生成
我有一个名为Server
的控制器,以及2个动作方法,分别叫做Search
和Component
。我有以下的路由配置:
routes.MapRoute("Component",
"{controller}/{serverId}/{action}",
new { controller = "Server", action = "Component" },
new { serverId = @"\d+" });
我找类似网址:
/Server/12345/Component
我的搜索操作方法:
return RedirectToAction("Component", new { serverId = 12345 });
我的组件的操作方法:
public ActionResult Component(int serverId)
{
return View();
}
The生成的网址是:
/Server/12345/
这是错误的,它是遗漏了“组件”。为什么是这样?
在一个侧面说明,这是一个伟大的事情来测试你的路线:http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx – Yahya 2013-03-15 10:37:07