我也可以這樣來配置我的路線在我的Global.asaxhtml.actionlink沒有創造右連桿
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"poems-by-profile", // Route name
"profile/{id}/{name}/poems", // URL with parameters
new { controller = "poems", action = "Index", id = "", name = "" } // Parameter defaults
);
routes.MapRoute(
"profile", // Route name
"profile/{id}/{name}", // URL with parameters
new { controller = "profile", action = "Index", id = "", name = "" } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}/{name}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional, name = UrlParameter.Optional } // Parameter defaults
);
這裏是我的兩個控制器
public class ProfileController : BaseController
{
public ActionResult Index(int id, string name)
{
return View();
}
}
public class PoemsController : BaseController
{
public ActionResult Index(int id, string name)
{
return View();
}
}
某處主頁上,我有HTML動作鏈接這樣
@Html.ActionLink("Profile", "index", "Profile", new { id = 1, name = "someuser" })
@Html.ActionLink("Poems by ", "index", "poems", new { id = 1, name = "someuser" })
我期待兩個網址類似
http://localhost/profile/1/someuser
http://localhost/profile/1/someuser/poems
但它不創建這些網址。
我做錯了什麼。
幫助將不勝感激。
//這裏更新我的問題
其實這一個工程
@Html.ActionLink("Profile", "index", "Profile", new { id = 1, name = "someuser" },null)
@Html.ActionLink("Poems by ", "index", "poems", new { id = 1, name = "some user" },null)
傳遞null作爲最後一個參數。
不知道爲什麼,但它的作品。
乾杯
成員Parminder
你有什麼實際生成的鏈接? – 2012-01-07 07:34:08
@ Floradu88它生成主頁鏈接(http:// localhost /) – Parminder 2012-01-07 07:48:36