2012-01-07 62 views
0

我也可以這樣來配置我的路線在我的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

+1

你有什麼實際生成的鏈接? – 2012-01-07 07:34:08

+0

@ Floradu88它生成主頁鏈接(http:// localhost /) – Parminder 2012-01-07 07:48:36

回答

1

嘗試

@Html.ActionLink("Profile", "index", new {controller="Profile" id = 1, name = "someuser" }) 
+0

謝謝,3nigma。有用。我更新了我的問題。所以還有一個選項也適用。 – Parminder 2012-01-07 07:45:46

+2

3nigma至少在一段時間內無法專注於你的考試:P – 2012-01-07 07:49:11

+0

@MuhammadAdeelZahid Wo0ps !!!破獲!!!! – Rafay 2012-01-07 07:50:26