2011-06-29 2 views
0

2つのIDを持つアクションリンクを作成するにはどうすればよいですか。 (私は地域を使用しています)。 Id2はクエリ文字列としてレンダリングされます。/Controller/Action/Id/Id2のアクションリンク

コントローラ

public ActionResult View(int id, int id2) 

ルート

context.MapRoute(
    "Admin_default", 
    "Admin/{controller}/{action}/{id}", 
    new { action = "Index", id = UrlParameter.Optional } 
); 

context.MapRoute(
    "Admin_default2", 
    "Admin/{controller}/{action}/{id}/{id2}", 
    new { action = "Index"} 
); 

ActionLinkの

@Html.ActionLink("Click", "News/View", new { area = "Admin", id = 1, id2 = 2 }, null) 

レンダリングリンク

/Admin/News/View/1?id2=2 

予想されるリンク

/Admin/News/View/1/2 

答えて

1

最初のより具体的なルート(Admin_default2)を追加してみてください。

だから、あなたのマッピングのコードは次のようになります。

context.MapRoute(
    "Admin_default2", 
    "Admin/{controller}/{action}/{id}/{id2}", 
    new { action = "Index"} 
); 

context.MapRoute(
    "Admin_default", 
    "Admin/{controller}/{action}/{id}", 
    new { action = "Index", id = UrlParameter.Optional } 
); 
関連する問題