請務必UrlParameter.Optional
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
標記您的選購PARAMS就是這個問題對我們(症狀爲你)。
- 編輯 這不是唯一的問題。 當遷移到MVC 3,你可以得到下一個問題, 假設你有這樣的路線(id
和page
是可選)
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}/{page}", // URL with parameters
new { controller = "Home", action = "Index", id = "", page = "" } // Parameter defaults
);
現在你必須把它分成2條不同的路線:
routes.MapRoute(
"Paged", // Route name
"{controller}/{action}/{id}/{page}",
new { controller = "Home", action = "Index", page = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional}//, page = UrlParameter.Optional } // Parameter defaults
);
升級到.NET 4.0時,「ActionLink」呈現的HTML是什麼,它與.NET 3.5中生成的HTML有什麼不同? – 2010-12-12 15:22:02
是的 - 即時通訊3.5我得到的鏈接與href的行動,在.net 4我得到沒有......發送我的網站的路線。 – SteveCl 2010-12-12 16:04:51
也試過Url.Action和相同。 我的意思是控制器的根,所以http:// site/controller / – SteveCl 2010-12-12 16:06:32