1

MvcSiteMapProvider を使用して、Asp.net MVC 4 でツリービュー ナビゲーターを作成しています

次のような2つのリンクがあります:

~/Home/Article/{id} および ~/Home/Gallery/{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();
    } 

それで成功しましたが、問題は ~/Home/Article/123 があり、 ~/Home/Gallery/456 に行くときです

次に、ツリービューをクリックして記事に戻ります。記事に間違った ID パラメータが設定されています。記事の Id に設定されたギャラリーの ID が ~/Home/Article/456 のように取得されます。

誰でもソルバーを持っていますか?私の英語でごめんなさい、それは悪いです。

4

1 に答える 1

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

于 2013-04-27T04:37:40.447 に答える