我正在使用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