2
我有以下的自定義URL路由規則:ASP.NET MVC 3 URL路徑問題定義路由
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"RaceRoute", // Route name
"people/create/{raceid}/{id}", // URL with parameters
new { controller = "People", action = "Create", raceid = UrlParameter.Optional, id = UrlParameter.Optional }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
我敢嘗試與ActionLink的
使用@Html.ActionLink("Add Person", "Create", "People", new { raceid = item.RaceId, id="1" })
我基本上希望URL看起來像 「/人/製作/ 5/1」
但生成的HTML看起來像
<a href="/races/Create?Length=6" id="1" raceid="5">Add Person</a>
應該說<a href="/people/Create/5/1">Add Person</a>
我的網頁是http://localhost:57355/races
如果我這樣做只是@Html.ActionLink("Add Person", "Create", "People")
那麼它的工作原理,但我沒有得到任何參數。
我錯過了什麼?
感謝
非常感謝您的幫助。 – Mike 2011-03-18 18:07:53