2013-04-27 33 views
1

我使用MvcSiteMapProvider在Asp.net MVC創建樹狀導航拿錯Id參數4MvcSiteMapProvider

我有2個鏈接,如:

〜/首頁/文/(編號)和 〜/主頁/圖庫/ {ID}

我像樹視圖:首頁 - >文章 - >畫廊

而且我用控制器

[MvcSiteMapNode(Title = "Article", ParentKey = "Home", Key="Article", PreservedRouteParameters="id")] 
    public ActionResult Article(int id) 
    { 
     ViewBag.Id = id; 
     return View(); 
    } 
    [MvcSiteMapNode(Title = "Gallery", Key="Gallery" ParentKey = "Article", PreservedRouteParameters="id")] 
    public ActionResult Gallery(int id) 
    { 
     ViewBag.id = id; 
     return View(); 
    } 
動態代碼

所以它運行成功,但問題是當我有 〜/主頁/條/ 123和我去〜/主頁/庫/ 456

接下來,我點擊樹狀回去文章,它設置錯誤文章中的ID參數,它爲文章的ID獲取Gallery的id設置:〜/ Home/Article/456。

任何人都有解決?對不起,我的英語很糟糕。

+0

此bug已被固定在4.0.5。有一條通過邏輯的路徑導致在已解決的無效節點上發生匹配。 – NightOwl888 2013-08-10 23:11:53

回答

0

您可以明確設置參數的名稱。

例如,

[MvcSiteMapNode(Title = "Article", ParentKey = "Home", Key="Article", PreservedRouteParameters="ArticleId")] 
public ActionResult Article(int ArticleId) 
{ 
    ViewBag.Id = ArticleId; 
    return View(); 
} 

[MvcSiteMapNode(Title = "Gallery", Key="Gallery" ParentKey = "Article", PreservedRouteParameters="GalleryId")] 
public ActionResult Gallery(int GalleryId) 
{ 
    ViewBag.id = GalleryId; 
    return View(); 
} 

然後:

/Home/Article/123

/Home/Gallery?GalleryId=456&ArticleId=123

+0

是的,我看到,但問題,如果我有很多參數像/首頁/文章/ {id}?name =「」&email =「」和/ Home/Gallery/{Galleryid}?name =「」&email =「」。所以我會改變所有的參數名稱? /主頁/庫/ {} Galleryid?GalleryName = 「」 &Galleryemail = 「」。對,它不友善。非常感謝您的迴應 – 2013-04-27 04:48:31