2010-11-05 63 views
1

我想用MvcSiteMap來定義我的控制器和動作的地圖,讓我產生面包屑和菜單ASP.Net MVC2站點地圖結點。如何創建使用MvcSiteMap

我已經使用下面的裝飾以編程方式添加節點試過,但不幸的是它不會讓我的樹像我想要的。

[MvcSiteMapNodeAttribute(Title = "Home"] 
[MvcSiteMapNodeAttribute(Title = "Services", ParentKey = "Home")] 
[MvcSiteMapNodeAttribute(Title = "Service detail", ParentKey = "Services")] 
[MvcSiteMapNodeAttribute(Title = "Edit", ParentKey = "Service detail")] 

我該如何裝飾自己的行爲以確保孩子/家長之間的關係是如何實現的?

[HandleError] 
public class HomeController : Controller 
{ 
    // Home 
    public ActionResult Index() 
    { 
     return View(); 
    } 
} 

[HandleError] 
public class ServiceController : Controller 
{ 
    // Home > Services 
    public ActionResult Index() 
    { 
     return View(); 
    } 

    // Home > Services > Service detail 
    public ActionResult Details (int id) 
    { 
     return View(); 
    } 

    // Home > Services > Service detail > Edit 
    public ActionResult Edit (int id) 
    { 
     return View(); 
    } 
} 

回答

0

你必須設定鍵,以及:

[MvcSiteMapNodeAttribute(Key = "Home", Title = "Home"] 
[MvcSiteMapNodeAttribute(Key = "Services", Title = "Services", ParentKey = "Home")] 
[MvcSiteMapNodeAttribute(Key = "ServiceDetail", Title = "Service detail", ParentKey = "Services")] 
[MvcSiteMapNodeAttribute(Title = "Edit", ParentKey = "ServiceDetail")]